src/main/java/com/mzl/flower/dto/request/supplier/QuerySupplierSubDTO.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mzl/flower/dto/request/supplier/SupplierSubDTO.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mzl/flower/dto/response/supplier/SupplierSubVO.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mzl/flower/entity/supplier/SupplierSub.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mzl/flower/mapper/supplier/SupplierSubMapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/mzl/flower/web/supplier/SupplierSubController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/mapper/supplier/SupplierSubMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/mzl/flower/dto/request/supplier/QuerySupplierSubDTO.java
对比新文件 @@ -0,0 +1,41 @@ package com.mzl.flower.dto.request.supplier; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data public class QuerySupplierSubDTO { @ApiModelProperty("供应商子账号ID") private Long id; @ApiModelProperty("供应商ID") private Long supplierId; @ApiModelProperty("供应商ID名称") private String supplierName; @ApiModelProperty("主账号手机号") private String supplierPhone; @ApiModelProperty("子账号手机号") private String phone; // @ApiModelProperty("申请时间(yyyy-mm-dd)") // private String createDateBeginStr; // // @ApiModelProperty("申请时间(yyyy-mm-dd)") // private String createDateEndStr; @ApiModelProperty("启用/禁用(USER_ENABLED_OR_DISABLED)") private Integer isEnabled; // @ApiModelProperty(value = "申请时间(yyyy-mm-dd)", hidden = true) // private LocalDateTime createDateBegin; // // @ApiModelProperty(value = "申请时间(yyyy-mm-dd)", hidden = true) // private LocalDateTime createDateEnd; } src/main/java/com/mzl/flower/dto/request/supplier/SupplierSubDTO.java
对比新文件 @@ -0,0 +1,28 @@ package com.mzl.flower.dto.request.supplier; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data public class SupplierSubDTO { private Long id; @ApiModelProperty("供应商ID(父ID)") private Long supplierId; @ApiModelProperty("子账号名称") private String name; @ApiModelProperty("子账号联系人") private String contact; @ApiModelProperty("子账号手机号") private String phone; @ApiModelProperty("子账号密码") private String password; @ApiModelProperty("启用/禁用") private Boolean isEnabled; } src/main/java/com/mzl/flower/dto/response/supplier/SupplierSubVO.java
对比新文件 @@ -0,0 +1,41 @@ package com.mzl.flower.dto.response.supplier; import com.mzl.flower.base.AbstractTransDTO; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.Date; @Data public class SupplierSubVO extends AbstractTransDTO { private Long id; @ApiModelProperty("供应商ID") private String supplierId; @ApiModelProperty("供应商ID名称") private String supplierName; @ApiModelProperty("供应商联系人") private String contactName; @ApiModelProperty("主账号(手机号)") private String contactTel; @ApiModelProperty("子账号名称") private String name; @ApiModelProperty("子账号手机号") private String phone; @ApiModelProperty("子账号联系人") private String contact; @ApiModelProperty("创建时间") private Date createTime; @ApiModelProperty("启用/禁用") private Boolean isEnabled; } src/main/java/com/mzl/flower/entity/supplier/SupplierSub.java
对比新文件 @@ -0,0 +1,35 @@ package com.mzl.flower.entity.supplier; import com.baomidou.mybatisplus.annotation.TableName; import com.mzl.flower.base.BaseAutoEntity; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.time.LocalDateTime; @Data @TableName("t_supplier_sub_info") public class SupplierSub extends BaseAutoEntity { @ApiModelProperty("供应商ID(父ID)") private String userId; @ApiModelProperty("供应商ID(父ID)") private Long supplierId; @ApiModelProperty("子账号名称") private String name; @ApiModelProperty("子账号联系人") private String contact; @ApiModelProperty("子账号手机号") private String phone; @ApiModelProperty("子账号密码") private String password; @ApiModelProperty("启用/禁用") private Boolean isEnabled; } src/main/java/com/mzl/flower/mapper/supplier/SupplierSubMapper.java
对比新文件 @@ -0,0 +1,16 @@ package com.mzl.flower.mapper.supplier; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mzl.flower.dto.request.supplier.QuerySupplierSubDTO; import com.mzl.flower.dto.response.supplier.SupplierSubVO; import com.mzl.flower.entity.supplier.SupplierSub; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import java.util.List; @Repository public interface SupplierSubMapper extends BaseMapper<SupplierSub> { List<SupplierSubVO> querySupplierSub(@Param("dto") QuerySupplierSubDTO dto, Page page); } src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java
对比新文件 @@ -0,0 +1,203 @@ package com.mzl.flower.service.supplier; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mzl.flower.config.exception.ValidationException; import com.mzl.flower.config.security.SecurityUtils; import com.mzl.flower.constant.Constants; import com.mzl.flower.dto.request.register.RegisterDTO; import com.mzl.flower.dto.request.supplier.QuerySupplierSubDTO; import com.mzl.flower.dto.request.supplier.SupplierSubDTO; import com.mzl.flower.dto.response.supplier.SupplierDTO; import com.mzl.flower.dto.response.supplier.SupplierSubVO; import com.mzl.flower.entity.supplier.SupplierSub; import com.mzl.flower.entity.system.User; import com.mzl.flower.mapper.supplier.SupplierSubMapper; import com.mzl.flower.mapper.system.UserMapper; import com.mzl.flower.service.BaseService; import com.mzl.flower.utils.DateUtils; import com.mzl.flower.utils.UUIDGenerator; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.List; @Service @Transactional @RequiredArgsConstructor public class SupplierSubService { private final SupplierSubMapper supplierSubMapper; private final PasswordEncoder passwordEncoder; private final UserMapper userMapper; private final BaseService baseService; public void addOrUpdateSupplier(SupplierSubDTO dto) { SupplierSub supplierSub; if (dto.getId() == null) { if (StringUtils.isEmpty(dto.getSupplierId())) { throw new ValidationException("供应商主账号ID不能为空"); } //检查该供应商下是否有名称一样的子账号 if (checkExistName(dto.getName(), dto.getSupplierId())) { throw new ValidationException("子账号名称已存在"); } //检查手机号 String userType = Constants.USER_TYPE.supplier.name(); if (checkUserExist(dto.getPhone(), userType)) { throw new ValidationException("该手机号码已经注册"); } supplierSub = new SupplierSub(); BeanUtils.copyProperties(dto, supplierSub, "id"); supplierSub.create(SecurityUtils.getUserId()); supplierSub.setIsEnabled(true); //用户信息注册 RegisterDTO registerDTO = new RegisterDTO(); registerDTO.setTel(supplierSub.getPhone()); String uuid = UUIDGenerator.getUUID(); String password = passwordEncoder.encode(supplierSub.getPassword()); registerDTO.setPassword(password); registerUser(registerDTO, uuid, password); supplierSub.setUserId(uuid); //保存子账号信息 supplierSubMapper.insert(supplierSub); } else { supplierSub = supplierSubMapper.selectById(dto.getId()); if (supplierSub == null) { throw new ValidationException("供应商子信息未登记"); } if (!StringUtils.isEmpty(dto.getName()) && !dto.getName().equals(supplierSub.getName())) { if (checkExistName(dto.getName(), supplierSub.getSupplierId())) { throw new ValidationException("子账号名称已存在"); } supplierSub.setName(dto.getName()); } if (!StringUtils.isEmpty(dto.getContact()) && !dto.getContact().equals(supplierSub.getContact())) { supplierSub.setContact(dto.getContact()); } if (StringUtils.isEmpty(supplierSub.getUserId())) { throw new ValidationException("该账号用户信息未注册"); } User user = userMapper.selectById(supplierSub.getUserId()); if (!StringUtils.isEmpty(dto.getPhone()) && !dto.getPhone().equals(supplierSub.getPhone())) { String userType = Constants.USER_TYPE.supplier.name(); if (checkUserExist(dto.getPhone(), userType)) { throw new ValidationException("该手机号码已经注册"); } supplierSub.setPhone(dto.getPhone()); } if (!StringUtils.isEmpty(dto.getPassword())) { //判断密码是否一致 if (!ObjectUtils.isEmpty(user)) { String encode = passwordEncoder.encode(dto.getPassword()); if (!encode.equals(user.getPassword())) { user.setPassword(encode); userMapper.updateById(user); supplierSub.setPassword(encode); } } } if (!StringUtils.isEmpty(dto.getPhone())) { if (!ObjectUtils.isEmpty(user)) { user.setLoginName(dto.getPhone()); user.setTel(dto.getPhone()); user.setNickName(dto.getPhone()); userMapper.updateById(user); } } supplierSub.setIsEnabled(supplierSub.getIsEnabled()); supplierSub.update(SecurityUtils.getUserId()); supplierSubMapper.updateById(supplierSub); } } private boolean checkExistName(String name, Long supplierId) { if (StringUtils.isEmpty(name)) { LambdaQueryWrapper<SupplierSub> lambdaQueryWrapper = new LambdaQueryWrapper(); lambdaQueryWrapper.eq(SupplierSub::getName, name).eq(SupplierSub::getSupplierId, supplierId); return supplierSubMapper.selectCount(lambdaQueryWrapper) > 0; } return false; } public Page<SupplierDTO> querySupplier(QuerySupplierSubDTO dto, Page page) { List<SupplierSubVO> list = supplierSubMapper.querySupplierSub(dto, page); page.setRecords(list); return page; } public void isEnable(Long id) { SupplierSub supplierSub = supplierSubMapper.selectById(id); if (supplierSub == null) { throw new ValidationException("供应商信息不存在"); } if (supplierSub.getIsEnabled()) { supplierSub.setIsEnabled(false); //强制下线 baseService.removeToken(supplierSub.getUserId()); } else { supplierSub.setIsEnabled(true); } supplierSub.update(SecurityUtils.getUserId()); supplierSubMapper.updateById(supplierSub); } public void registerUser(RegisterDTO dto, String uuid, String password) { User user = new User(); user.setId(uuid); user.setLoginName(dto.getTel()); user.setTel(dto.getTel()); user.setNickName(dto.getTel()); user.setPassword(password); user.setType(Constants.USER_TYPE.supplier.name()); user.setStatus(Constants.STATUS_ACTIVE); user.setIsSys(Constants.N); user.create(); userMapper.insert(user); } //供应商手机号唯一,主子不能用同一个手机号 private boolean checkUserExist(String tel, String userType) { List<String> userTypes = new ArrayList<>(); userTypes.add(userType); User user = userMapper.getActiveUser(tel, userTypes); return user != null; } public void delete(Long id) { SupplierSub supplierSub = supplierSubMapper.selectById(id); if (!ObjectUtils.isEmpty(supplierSub)) { if (!StringUtils.isEmpty(supplierSub.getUserId())) { //删除用户表信息 userMapper.deleteById(supplierSub.getUserId()); } //删除供应商子表信息 supplierSubMapper.deleteById(id); } } } src/main/java/com/mzl/flower/web/supplier/SupplierSubController.java
对比新文件 @@ -0,0 +1,60 @@ package com.mzl.flower.web.supplier; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mzl.flower.base.BaseController; import com.mzl.flower.base.R; import com.mzl.flower.base.ReturnDataDTO; import com.mzl.flower.dto.request.supplier.*; import com.mzl.flower.service.supplier.SupplierSubService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.constraints.NotNull; @RestController @RequestMapping("/api/supplierSub") @Api(value = "供应商子账号管理", tags = "供应商子账号管理") @Validated @Slf4j public class SupplierSubController extends BaseController { private final SupplierSubService supplierSubService; public SupplierSubController(SupplierSubService supplierSubService) { this.supplierSubService = supplierSubService; } @PostMapping("/addOrUpdate") @ApiOperation(value = "供应商子账号信息登记、修改", notes = "供应商信息子账号登记、修改") public ResponseEntity<ReturnDataDTO> addOrUpdateSupplier(@Validated @RequestBody SupplierSubDTO dto) { supplierSubService.addOrUpdateSupplier(dto); return returnData(R.SUCCESS.getCode(), null); } @GetMapping("/page") @ApiOperation(value = "运营端-供应商子账号分页查询", notes = "运营端-供应商子账号分页查询") public ResponseEntity<ReturnDataDTO<Page<SupplierSubDTO>>> querySupplier(QuerySupplierSubDTO dto, Page page) { return returnData(R.SUCCESS.getCode(), supplierSubService.querySupplier(dto, page)); } @GetMapping("/page/isEnable") @ApiOperation(value = "子账号启用/禁用", notes = "子账号启用/禁用") public ResponseEntity<ReturnDataDTO<String>> isEnable(@NotNull(message = "id不能为空") Long id) { supplierSubService.isEnable(id); return returnData(R.SUCCESS.getCode(), null); } @PostMapping("/delete/{id}") @ApiOperation(value = "子账号删除", notes = "子账号删除") public ResponseEntity<ReturnDataDTO> delete(@PathVariable("id") Long id) { supplierSubService.delete(id); return returnData(R.SUCCESS.getCode(), null); } } src/main/resources/mapper/supplier/SupplierSubMapper.xml
对比新文件 @@ -0,0 +1,48 @@ <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.mzl.flower.mapper.supplier.SupplierSubMapper"> <select id="querySupplierSub" resultType="com.mzl.flower.dto.response.supplier.SupplierSubVO"> SELECT t.*,s.name as supplierName,s.contact_name as contactName,s.contact_tel as contactTel FROM t_supplier_sub_info t LEFT JOIN t_supplier_info s ON t.supplier_id = s.id WHERE t.deleted = 0 <if test="dto.supplierId!=null "> AND t.supplier_id =#{dto.supplierId} </if> <if test="dto.supplierName!=null and dto.supplierName!=''"> AND s.name LIKE CONCAT('%',#{dto.supplierName}, '%') </if> <if test="dto.supplierPhone!=null and dto.supplierPhone!=''"> AND s.contact_tel LIKE CONCAT('%',#{dto.supplierPhone}, '%') </if> <if test="dto.phone!=null and dto.phone!=''"> AND t.phone LIKE CONCAT('%',#{dto.phone}, '%') </if> <!-- <if test="dto.createDateBegin!=null ">--> <!-- <![CDATA[--> <!-- AND t.create_time >= #{dto.createDateBegin}--> <!-- ]]>--> <!-- </if>--> <!-- <if test="dto.createDateEnd!=null ">--> <!-- <![CDATA[--> <!-- AND t.create_time <= #{dto.createDateEnd}--> <!-- ]]>--> <!-- </if>--> <if test="dto.isEnabled!=null"> AND t.is_enabled = #{dto.isEnabled} </if> <if test="dto.id!=null"> AND t.id = #{dto.id} </if> order by t.create_time desc </select> </mapper>