Browse Source

客户欠款的交易

Signed-off-by: fengb <fengbin1989@aliyun.com>
cangku
fengb 3 years ago
parent
commit
75b0e681f9
  1. 44
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CustomerController.java
  2. 22
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/PurchaseController.java
  3. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/CustomerMapper.java
  4. 4
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/PurchaseMapper.java
  5. 25
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/DebtCustomer.java
  6. 25
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/DebtSupplier.java
  7. 4
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/CustomerService.java
  8. 4
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/PurchaseService.java
  9. 13
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/CustomerServiceImpl.java
  10. 12
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseServiceImpl.java
  11. 16
      hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml
  12. 34
      hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseMapper.xml

44
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CustomerController.java

@ -1,19 +1,30 @@
package cc.hiver.mall.controller; package cc.hiver.mall.controller;
import cc.hiver.core.common.utils.PageUtil;
import cc.hiver.core.common.utils.ResultUtil; import cc.hiver.core.common.utils.ResultUtil;
import cc.hiver.core.common.utils.StringUtils; import cc.hiver.core.common.utils.StringUtils;
import cc.hiver.core.common.vo.PageVo;
import cc.hiver.core.common.vo.Result; import cc.hiver.core.common.vo.Result;
import cc.hiver.core.entity.Role;
import cc.hiver.core.entity.User; import cc.hiver.core.entity.User;
import cc.hiver.core.entity.UserRole;
import cc.hiver.core.service.RoleService;
import cc.hiver.core.service.UserRoleService;
import cc.hiver.core.service.UserService; import cc.hiver.core.service.UserService;
import cc.hiver.mall.entity.Customer; import cc.hiver.mall.entity.Customer;
import cc.hiver.mall.pojo.dto.DebtCustomer;
import cc.hiver.mall.service.mybatis.CustomerService; import cc.hiver.mall.service.mybatis.CustomerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -32,10 +43,23 @@ public class CustomerController {
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private UserRoleService userRoleService;
@Autowired
private RoleService roleService;
@RequestMapping(value = "/save", method = RequestMethod.POST) @RequestMapping(value = "/save", method = RequestMethod.POST)
@ApiOperation(value = "新增客户") @ApiOperation(value = "新增客户")
@Transactional
public Result save(Customer customer) { public Result save(Customer customer) {
boolean result =true;
User byUsername = userService.findByUsername(customer.getUserName());
User byMobile = userService.findByMobile(customer.getPhone());
if (!ObjectUtils.isEmpty(byUsername) || !ObjectUtils.isEmpty(byMobile)){
return ResultUtil.error("该账号或手机号已存在。");
}
String encryptPass = new BCryptPasswordEncoder().encode("123456");//默认密码 String encryptPass = new BCryptPasswordEncoder().encode("123456");//默认密码
User user = new User(); User user = new User();
user.setUsername(customer.getUserName()); user.setUsername(customer.getUserName());
@ -47,8 +71,17 @@ public class CustomerController {
user.setPassword(encryptPass); user.setPassword(encryptPass);
User saveUser = userService.save(user); User saveUser = userService.save(user);
customer.setUserId(saveUser.getId()); customer.setUserId(saveUser.getId());
boolean result = customerService.save(customer); result = customerService.save(customer);
UserRole userRole = new UserRole();
PageVo pageVo = new PageVo();
pageVo.setPageNumber(1);
pageVo.setPageSize(1);
Page<Role> rolePage = roleService.findByCondition("ROLE_CUSTOMER", PageUtil.initPage(pageVo));
Role role = rolePage.getContent().get(0);
userRole.setRoleId(role.getId());//客户角色
userRole.setRoleName("客户");
userRole.setUserId(saveUser.getId());
userRoleService.save(userRole);
if(result) { if(result) {
return ResultUtil.success("添加成功"); return ResultUtil.success("添加成功");
} else { } else {
@ -111,4 +144,11 @@ public class CustomerController {
} }
@RequestMapping(value = "/debt", method = RequestMethod.GET)
@ApiOperation(value = "查询欠款客户列表")
public Result debt(String shopId) {
List<DebtCustomer> list = customerService.debt(shopId);
return new ResultUtil<List<DebtCustomer>>().setData(list);
}
} }

22
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/PurchaseController.java

@ -5,6 +5,7 @@ import cc.hiver.core.common.utils.StringUtils;
import cc.hiver.core.common.vo.Result; import cc.hiver.core.common.vo.Result;
import cc.hiver.mall.entity.Purchase; import cc.hiver.mall.entity.Purchase;
import cc.hiver.mall.entity.PurchaseDetail; import cc.hiver.mall.entity.PurchaseDetail;
import cc.hiver.mall.pojo.dto.DebtSupplier;
import cc.hiver.mall.pojo.vo.PurchaseVo; import cc.hiver.mall.pojo.vo.PurchaseVo;
import cc.hiver.mall.service.mybatis.PurchaseDetailService; import cc.hiver.mall.service.mybatis.PurchaseDetailService;
import cc.hiver.mall.service.mybatis.PurchaseService; import cc.hiver.mall.service.mybatis.PurchaseService;
@ -94,4 +95,25 @@ public class PurchaseController {
return new ResultUtil<List<Purchase>>().setData(list); return new ResultUtil<List<Purchase>>().setData(list);
} }
@RequestMapping(value = "/debt", method = RequestMethod.GET)
@ApiOperation(value = "根据商铺id查询上游欠款供应商列表")
public Result debt(String shopId) {
List<DebtSupplier> list = purchaseService.getDebtByShopId(shopId);
return new ResultUtil<List<DebtSupplier>>().setData(list);
}
@RequestMapping(value = "/debtPurchase", method = RequestMethod.GET)
@ApiOperation(value = "查询供应商的欠款采购单列表")
public Result list(String supplierId) {
QueryWrapper<Purchase> queryWrapper = new QueryWrapper<>();
queryWrapper.ge("no_pay",0);
queryWrapper.eq("supplier_id",supplierId);
List<Purchase> list = purchaseService.list(queryWrapper);
return new ResultUtil<List<Purchase>>().setData(list);
}
} }

3
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/CustomerMapper.java

@ -2,6 +2,7 @@ package cc.hiver.mall.dao.mapper;
import cc.hiver.mall.entity.Customer; import cc.hiver.mall.entity.Customer;
import cc.hiver.mall.entity.CustomerExample; import cc.hiver.mall.entity.CustomerExample;
import cc.hiver.mall.pojo.dto.DebtCustomer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -31,4 +32,6 @@ public interface CustomerMapper extends BaseMapper<Customer> {
int updateByPrimaryKeySelective(Customer record); int updateByPrimaryKeySelective(Customer record);
int updateByPrimaryKey(Customer record); int updateByPrimaryKey(Customer record);
List<DebtCustomer> selectDebtByShopId(String shopId);
} }

4
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/PurchaseMapper.java

@ -2,6 +2,7 @@ package cc.hiver.mall.dao.mapper;
import cc.hiver.mall.entity.Purchase; import cc.hiver.mall.entity.Purchase;
import cc.hiver.mall.entity.PurchaseExample; import cc.hiver.mall.entity.PurchaseExample;
import cc.hiver.mall.pojo.dto.DebtSupplier;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -30,4 +31,7 @@ public interface PurchaseMapper extends BaseMapper<Purchase> {
int updateByPrimaryKeySelective(Purchase record); int updateByPrimaryKeySelective(Purchase record);
int updateByPrimaryKey(Purchase record); int updateByPrimaryKey(Purchase record);
List<DebtSupplier> selectDebtByShopId(String shopId);
} }

25
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/DebtCustomer.java

@ -0,0 +1,25 @@
package cc.hiver.mall.pojo.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @类描述
* @作者 冯彬
* @时间 2023/9/19-下午10:05
*/
@Data
public class DebtCustomer {
@ApiModelProperty(value = "用户ID")
private String userId;
@ApiModelProperty(value = "用户名称")
private String nickname;
@ApiModelProperty(value = "欠款金额")
private BigDecimal no_earn;
}

25
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/dto/DebtSupplier.java

@ -0,0 +1,25 @@
package cc.hiver.mall.pojo.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @类描述
* @作者 冯彬
* @时间 2023/9/19-下午10:05
*/
@Data
public class DebtSupplier {
@ApiModelProperty(value = "供应商ID")
private String supplierId;
@ApiModelProperty(value = "供应商名称")
private String consigneeName;
@ApiModelProperty(value = "欠款金额")
private BigDecimal noPay;
}

4
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/CustomerService.java

@ -2,7 +2,11 @@ package cc.hiver.mall.service.mybatis;
import cc.hiver.mall.entity.Customer; import cc.hiver.mall.entity.Customer;
import cc.hiver.mall.entity.Product; import cc.hiver.mall.entity.Product;
import cc.hiver.mall.pojo.dto.DebtCustomer;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
public interface CustomerService extends IService<Customer> { public interface CustomerService extends IService<Customer> {
List<DebtCustomer> debt(String shopId);
} }

4
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/PurchaseService.java

@ -2,7 +2,11 @@ package cc.hiver.mall.service.mybatis;
import cc.hiver.mall.entity.ProductAttribute; import cc.hiver.mall.entity.ProductAttribute;
import cc.hiver.mall.entity.Purchase; import cc.hiver.mall.entity.Purchase;
import cc.hiver.mall.pojo.dto.DebtSupplier;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
public interface PurchaseService extends IService<Purchase> { public interface PurchaseService extends IService<Purchase> {
List<DebtSupplier> getDebtByShopId(String shopId);
} }

13
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/CustomerServiceImpl.java

@ -4,11 +4,24 @@ import cc.hiver.mall.dao.mapper.CustomerMapper;
import cc.hiver.mall.dao.mapper.ProductMapper; import cc.hiver.mall.dao.mapper.ProductMapper;
import cc.hiver.mall.entity.Customer; import cc.hiver.mall.entity.Customer;
import cc.hiver.mall.entity.Product; import cc.hiver.mall.entity.Product;
import cc.hiver.mall.pojo.dto.DebtCustomer;
import cc.hiver.mall.service.mybatis.CustomerService; import cc.hiver.mall.service.mybatis.CustomerService;
import cc.hiver.mall.service.mybatis.ProductService; import cc.hiver.mall.service.mybatis.ProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
@Service @Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService { public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
@Autowired
private CustomerMapper customerMapper;
@Override
public List<DebtCustomer> debt(String shopId) {
List<DebtCustomer> list = customerMapper.selectDebtByShopId(shopId);
return list;
}
} }

12
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/PurchaseServiceImpl.java

@ -4,11 +4,23 @@ import cc.hiver.mall.dao.mapper.ProductMapper;
import cc.hiver.mall.dao.mapper.PurchaseMapper; import cc.hiver.mall.dao.mapper.PurchaseMapper;
import cc.hiver.mall.entity.Product; import cc.hiver.mall.entity.Product;
import cc.hiver.mall.entity.Purchase; import cc.hiver.mall.entity.Purchase;
import cc.hiver.mall.pojo.dto.DebtSupplier;
import cc.hiver.mall.service.mybatis.ProductService; import cc.hiver.mall.service.mybatis.ProductService;
import cc.hiver.mall.service.mybatis.PurchaseService; import cc.hiver.mall.service.mybatis.PurchaseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
@Service @Service
public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> implements PurchaseService { public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> implements PurchaseService {
@Autowired
private PurchaseMapper purchaseMapper;
@Override
public List<DebtSupplier> getDebtByShopId(String shopId) {
return purchaseMapper.selectDebtByShopId(shopId);
}
} }

16
hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml

@ -18,6 +18,11 @@
<result column="shop_id" jdbcType="VARCHAR" property="shopId" /> <result column="shop_id" jdbcType="VARCHAR" property="shopId" />
<result column="user_id" jdbcType="VARCHAR" property="userId" /> <result column="user_id" jdbcType="VARCHAR" property="userId" />
</resultMap> </resultMap>
<resultMap id="DebtResultMap" type="cc.hiver.mall.pojo.dto.DebtCustomer">
<result column="user_id" jdbcType="VARCHAR" property="userId" />
<result column="nickname" jdbcType="VARCHAR" property="nickname" />
<result column="no_earn" jdbcType="DECIMAL" property="no_earn" />
</resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
<foreach collection="oredCriteria" item="criteria" separator="or"> <foreach collection="oredCriteria" item="criteria" separator="or">
@ -365,4 +370,15 @@
user_id = #{userId,jdbcType=VARCHAR} user_id = #{userId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
<select id="selectDebtByShopId" parameterType="java.lang.String" resultMap="DebtResultMap">
select a.user_id,b.nickname,sum(a.no_earn) as no_earn
from t_sale a
left join t_user b on a.user_id = b.id
where 1=1
and pay_status != 1
and shop_id = #{shopId,jdbcType=VARCHAR}
group by a.user_id,b.nickname
</select>
</mapper> </mapper>

34
hiver-modules/hiver-mall/src/main/resources/mapper/PurchaseMapper.xml

@ -15,6 +15,13 @@
<result column="already_pay" jdbcType="DECIMAL" property="alreadyPay" /> <result column="already_pay" jdbcType="DECIMAL" property="alreadyPay" />
<result column="no_pay" jdbcType="DECIMAL" property="noPay" /> <result column="no_pay" jdbcType="DECIMAL" property="noPay" />
</resultMap> </resultMap>
<resultMap id="DebtResultMap" type="cc.hiver.mall.pojo.dto.DebtSupplier">
<result column="supplier_id" jdbcType="VARCHAR" property="supplierId" />
<result column="consignee_name" jdbcType="VARCHAR" property="consigneeName" />
<result column="no_pay" jdbcType="DECIMAL" property="noPay" />
</resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
<foreach collection="oredCriteria" item="criteria" separator="or"> <foreach collection="oredCriteria" item="criteria" separator="or">
@ -74,7 +81,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, create_by, create_time, del_flag, update_by, update_time, supplier_id, shop_id, id, create_by, create_time, del_flag, update_by, update_time, supplier_id, shop_id,
total_amount, should_pay, already_pay, no_pay total_amount, should_pay, already_pay, no_pay
</sql> </sql>
<select id="selectByExample" parameterType="cc.hiver.mall.entity.PurchaseExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="cc.hiver.mall.entity.PurchaseExample" resultMap="BaseResultMap">
@ -92,7 +99,7 @@
</if> </if>
</select> </select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from t_purchase from t_purchase
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
@ -108,14 +115,14 @@
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="cc.hiver.mall.entity.Purchase"> <insert id="insert" parameterType="cc.hiver.mall.entity.Purchase">
insert into t_purchase (id, create_by, create_time, insert into t_purchase (id, create_by, create_time,
del_flag, update_by, update_time, del_flag, update_by, update_time,
supplier_id, shop_id, total_amount, supplier_id, shop_id, total_amount,
should_pay, already_pay, no_pay should_pay, already_pay, no_pay
) )
values (#{id,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, values (#{id,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{delFlag,jdbcType=INTEGER}, #{updateBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{delFlag,jdbcType=INTEGER}, #{updateBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP},
#{supplierId,jdbcType=VARCHAR}, #{shopId,jdbcType=VARCHAR}, #{totalAmount,jdbcType=DECIMAL}, #{supplierId,jdbcType=VARCHAR}, #{shopId,jdbcType=VARCHAR}, #{totalAmount,jdbcType=DECIMAL},
#{shouldPay,jdbcType=DECIMAL}, #{alreadyPay,jdbcType=DECIMAL}, #{noPay,jdbcType=DECIMAL} #{shouldPay,jdbcType=DECIMAL}, #{alreadyPay,jdbcType=DECIMAL}, #{noPay,jdbcType=DECIMAL}
) )
</insert> </insert>
@ -320,4 +327,15 @@
no_pay = #{noPay,jdbcType=DECIMAL} no_pay = #{noPay,jdbcType=DECIMAL}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
<select id="selectDebtByShopId" parameterType="java.lang.String" resultMap="DebtResultMap">
select a.supplier_id,b.consignee_name,sum(a.no_pay) no_pay
from t_purchase a
left join t_supplier b on a.supplier_id = b.id
where 1=1
and no_pay > 0
and shop_id = #{shopId,jdbcType=VARCHAR}
group by a.supplier_id,b.consignee_name
</select>
</mapper> </mapper>
Loading…
Cancel
Save