cloudroam
2024-12-04 2432594a4d11b47a503795349defa31872f85789
src/main/java/com/mzl/flower/service/flower/FlowerMarkupPsService.java
@@ -7,17 +7,22 @@
import com.mzl.flower.dto.request.flower.*;
import com.mzl.flower.dto.response.flower.*;
import com.mzl.flower.entity.flower.*;
import com.mzl.flower.entity.log.OperationRecord;
import com.mzl.flower.entity.partner.Partner;
import com.mzl.flower.mapper.flower.FlowerMarkupPsMapper;
import com.mzl.flower.mapper.flower.FlowerMarkupPsSpCgMapper;
import com.mzl.flower.mapper.flower.FlowerMarkupPsSpMapper;
import com.mzl.flower.mapper.log.OperationRecordMapper;
import com.mzl.flower.service.BaseService;
import com.mzl.flower.utils.IpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
@Slf4j
@@ -33,6 +38,9 @@
    @Autowired
    private FlowerMarkupPsSpMapper spMapper;
    @Autowired
    private OperationRecordMapper operationRecordMapper;
    public Long saveMarkupPs(FlowerMarkupPsSaveDTO dto){
        FlowerMarkupPs g = new FlowerMarkupPs();
@@ -66,7 +74,7 @@
        markupCacheClient.deleteAllPsSpCg(id);
    }
    public void saveMarkupSpCgBatch(FlowerMarkupPsSpCgBatchSaveDTO dto){
    public void saveMarkupSpCgBatch(FlowerMarkupPsSpCgBatchSaveDTO dto,HttpServletRequest request) throws IOException {
        List<Long> categoryIds = dto.getCategoryId();
        if(categoryIds == null || categoryIds.size() == 0){
            throw new ValidationException("分类列表不能为空");
@@ -77,26 +85,40 @@
            cg.setCategoryId(categoryId);
            saveMarkupSpCg(cg);
            saveMarkupSpCg(cg,request);
        }
    }
    public void saveMarkupSpCg(FlowerMarkupPsSpCgSaveDTO dto){
    public void saveMarkupSpCg(FlowerMarkupPsSpCgSaveDTO dto,HttpServletRequest request) throws IOException {
        Long cId = dto.getCategoryId();
        FlowerMarkupPsSpCg cg = spCgMapper.selectOne(new QueryWrapper<FlowerMarkupPsSpCg>()
                .eq("partner_id", dto.getPartnerId()).eq("category_id", cId));
        String content = "";
        OperationRecord operationRecord = new OperationRecord();
        if(cg == null){
            cg = new FlowerMarkupPsSpCg();
            BeanUtils.copyProperties(dto, cg);
            cg.setPartnerId(dto.getPartnerId());
            cg.create(SecurityUtils.getUserId());
            spCgMapper.insert(cg);
             content = "新增商品分类加价:商品分类Id:【" + cg.getCategoryId() + "】,A级:【"+cg.getLevelA()+"】,B级:【" + cg.getLevelB() + "】,C级:【" + cg.getLevelC() + "】" +
                    ",D级:【"+dto.getLevelD()+"】,E级:【" + cg.getLevelE() + "】,O级:【" + cg.getLevelO() + "】";
            operationRecord.setFunction("新增商品分类加价");
        } else {
            BeanUtils.copyProperties(dto, cg);
            cg.update(SecurityUtils.getUserId());
            spCgMapper.updateById(cg);
             content = "修改商品分类加价:id:【"+cg.getId()+"】,商品分类Id:【" + cg.getCategoryId() + "】,A级:【"+cg.getLevelA()+"】,B级:【" + cg.getLevelB() + "】,C级:【" + cg.getLevelC() + "】" +
                    ",D级:【"+dto.getLevelD()+"】,E级:【" + cg.getLevelE() + "】,O级:【" + cg.getLevelO() + "】";
            operationRecord.setFunction("修改商品分类加价");
        }
        markupCacheClient.addMarkupPsSpCg(dto.getPartnerId(), cId, cg);
        operationRecord.setContent(content);
        operationRecord.create(SecurityUtils.getUserId());
        operationRecord.setStatus("success");
        operationRecord.setModule("markup_s_p");
        operationRecord.setIpAddress(IpUtil.getIpAddress(request));
        operationRecordMapper.insert(operationRecord);
    }
    public FlowerMarkupPsSpCgDTO getMarkupSpCg(Long partnerId, Long categoryId){
@@ -125,9 +147,11 @@
        markupCacheClient.deleteMarkupPsSpCg(partnerId, categoryId);
    }
    public void saveMarkupSp(FlowerMarkupPsSpSaveDTO dto){
    public void saveMarkupSp(FlowerMarkupPsSpSaveDTO dto,HttpServletRequest request) throws IOException {
        FlowerMarkupPsSp sp = spMapper.selectOne(new QueryWrapper<FlowerMarkupPsSp>()
                .eq("partner_id", dto.getPartnerId()).eq("flower_id", dto.getFlowerId()));
        String content = "";
        OperationRecord operationRecord = new OperationRecord();
        if(sp == null){
            sp = new FlowerMarkupPsSp();
            sp.setFlowerId(dto.getFlowerId());
@@ -135,13 +159,23 @@
            sp.setPartnerId(dto.getPartnerId());
            sp.create(SecurityUtils.getUserId());
            spMapper.insert(sp);
            content = "新增商品加价:商品id:【" + dto.getFlowerId() + "】,合伙人id:【"+dto.getPartnerId()+"】,金额:【" + dto.getFee() + "】";
            operationRecord.setFunction("新增商品分类加价");
        } else {
            sp.setFee(dto.getFee());
            sp.update(SecurityUtils.getUserId());
            spMapper.updateById(sp);
            content = "修改商品加价:id:【"+sp.getId()+"】,商品id:【" + dto.getFlowerId() + "】,合伙人id:【"+dto.getPartnerId()+"】,金额:【" + dto.getFee() + "】";
        }
        markupCacheClient.addMarkupPsSp(dto.getPartnerId(), dto.getFlowerId(), sp);
        operationRecord.create(SecurityUtils.getUserId());
        operationRecord.setStatus("success");
        operationRecord.setModule("markup_s_p");
        operationRecord.setContent(content);
        operationRecord.setIpAddress(IpUtil.getIpAddress(request));
        operationRecordMapper.insert(operationRecord);
    }
    public FlowerMarkupSpDTO getMarkupSp(Long partnerId, Long flowerId){