123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package com.caimei.service.impl;
- import com.caimei.mapper.AuthMapper;
- import com.caimei.model.ResponseJson;
- import com.caimei.model.po.CmBrandAuthPo;
- import com.caimei.model.vo.AuthVo;
- import com.caimei.service.AuthProductService;
- import com.caimei.service.AuthService;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.util.Date;
- import java.util.List;
- import java.util.ListIterator;
- /**
- * Description
- *
- * @author : Aslee
- * @date : 2021/5/11
- */
- @Slf4j
- @Service
- public class AuthServiceImpl implements AuthService {
- @Resource
- private AuthMapper authMapper;
- private AuthProductService authProductService;
- @Autowired
- public void setAuthProductService(AuthProductService authProductService) {
- this.authProductService = authProductService;
- }
- @Override
- public ResponseJson<PageInfo<AuthVo>> getAuthList(Integer listType, Integer authUserId, String authParty, Integer status, Integer auditStatus, Integer lowerAuditStatus, Integer pageNum, Integer pageSize) {
- if (null == authUserId) {
- return ResponseJson.error("参数异常,请输入供应商用户id", null);
- }
- listType = null == listType ? 1 : listType;
- PageHelper.startPage(pageNum, pageSize);
- List<AuthVo> authList = authMapper.getAuthList(listType, authUserId, authParty, status, auditStatus);
- ListIterator<AuthVo> iterator = authList.listIterator();
- while (iterator.hasNext()) {
- AuthVo auth = iterator.next();
- Integer waitAuditNum = auth.getWaitAuditNum();
- if (waitAuditNum > 0) {
- auth.setLowerAuditStatus(0);
- if (null != lowerAuditStatus && 1 == lowerAuditStatus) {
- iterator.remove();
- }
- } else {
- auth.setLowerAuditStatus(1);
- if (null != lowerAuditStatus && 0 == lowerAuditStatus) {
- iterator.remove();
- }
- }
- }
- PageInfo<AuthVo> pageData = new PageInfo<>(authList);
- return ResponseJson.success(pageData);
- }
- @Override
- public ResponseJson updateAuthStatus(Integer authId, Integer status) {
- if (authId == null) {
- return ResponseJson.error("请输入授权id");
- }
- if (status == null) {
- return ResponseJson.error("请输入要更新的状态值");
- }
- authMapper.updateAuthStatusByAuthId(authId, status);
- if (status == 0) {
- return ResponseJson.success("下线品牌授权成功");
- } else {
- return ResponseJson.success("上线品牌授权成功");
- }
- }
- @Override
- public ResponseJson deleteAuth(Integer authId) {
- if (null == authId) {
- return ResponseJson.error("参数异常,请输入授权id");
- }
- // 删除品牌授权
- authMapper.deleteAuthByAuthId(authId);
- // 删除商品及商品参数
- List<Integer> productIdList = authProductService.getProductIdsByAuthId(authId);
- productIdList.forEach(productId->{
- if (null != productId) {
- authProductService.deleteProduct(productId);
- }
- });
- return ResponseJson.success("删除品牌授权成功");
- }
- @Override
- public ResponseJson saveAuth(Integer authId, Integer authUserId, String authParty, Integer createBy) {
- if (null == authUserId) {
- return ResponseJson.error("参数异常,请输入供应商用户id");
- }
- if (StringUtils.isBlank(authParty)) {
- return ResponseJson.error("参数异常,请输入授权机构名称");
- }
- if (null == createBy) {
- return ResponseJson.error("参数异常,请输入创建人id");
- }
- /*
- 组装授权数据
- */
- CmBrandAuthPo auth = new CmBrandAuthPo();
- auth.setAuthUserId(authUserId);
- auth.setAuthParty(authParty);
- // 保存品牌授权信息,上线状态默认为“待上线”,审核状态为“待审核”
- auth.setStatus(2);
- auth.setAuditStatus(2);
- if (null == authId) {
- auth.setCreateBy(createBy);
- auth.setCreateTime(new Date());
- } else {
- auth.setId(authId);
- }
- /*
- 保存授权
- */
- if (null == authId) {
- authMapper.insertAuth(auth);
- } else {
- authMapper.updateAuthByAuthId(auth);
- }
- return ResponseJson.success("保存品牌授权成功");
- }
- @Override
- public ResponseJson auditAuth(Integer authId, Integer auditStatus, String invalidReason, Integer auditBy) {
- if (authId == null) {
- return ResponseJson.error("请输入授权id");
- }
- if (auditStatus == null) {
- return ResponseJson.error("请输入审核结果");
- }
- if (auditStatus == 0 && StringUtils.isEmpty(invalidReason)) {
- return ResponseJson.error("请输入审核不通过的理由");
- }
- if (auditBy == null) {
- return ResponseJson.error("请输入审核人用户id");
- }
- Date auditTime = new Date();
- // 授权状态更新
- Integer status = null;
- if (auditStatus == 0) {
- // 审核不通过,下线授权
- status = 0;
- } else {
- // 审核通过,上线授权
- status = 1;
- }
- authMapper.updateAuthAuditStatus(authId, status, auditStatus, invalidReason, auditBy, auditTime);
- return ResponseJson.success("审核品牌授权成功");
- }
- }
|