xiexiang vor 1 Jahr
Ursprung
Commit
3e8b40bc71

+ 41 - 0
src/main/java/cn/cslg/pas/common/dto/business/ProductMarketDataDTO.java

@@ -0,0 +1,41 @@
+package cn.cslg.pas.common.dto.business;
+
+import lombok.Data;
+
+/**
+ * 新增产品营销数据
+ * @Author xiexiang
+ * @Date 2023/11/16
+ */
+@Data
+public class ProductMarketDataDTO {
+    /**
+     * 产品id
+     */
+    private Integer productId;
+
+    /**
+     * 营销时间
+     */
+    private String saleTime;
+
+    /**
+     * 营销地区
+     */
+    private String saleArea;
+
+    /**
+     * 销售量
+     */
+    private Double saleCount;
+
+    /**
+     * 销售额(万元)
+     */
+    private Double saleMoney;
+
+    /**
+     * 自定义许可费率
+     */
+    private Double customLicenseRate;
+}

+ 48 - 0
src/main/java/cn/cslg/pas/common/dto/business/UpdateProductMarketDataDTO.java

@@ -0,0 +1,48 @@
+package cn.cslg.pas.common.dto.business;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 更新产品营销数据DTO
+ * @Author xiexiang
+ * @Date 2023/11/16
+ */
+@Data
+public class UpdateProductMarketDataDTO {
+    /**
+     * id
+     */
+    private Integer id;
+
+    /**
+     * 产品id
+     */
+    private Integer productId;
+
+    /**
+     * 营销时间
+     */
+    private String saleTime;
+
+    /**
+     * 营销地区
+     */
+    private String saleArea;
+
+    /**
+     * 销售量
+     */
+    private Double saleCount;
+
+    /**
+     * 销售额(万元)
+     */
+    private Double saleMoney;
+
+    /**
+     * 自定义许可费率
+     */
+    private Double customLicenseRate;
+}

+ 54 - 0
src/main/java/cn/cslg/pas/common/vo/business/ProductMarketDataVO.java

@@ -0,0 +1,54 @@
+package cn.cslg.pas.common.vo.business;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 查询产品营销数据VO类
+ * @Author xiexiang
+ * @Date 2023/11/16
+ */
+@Data
+public class ProductMarketDataVO {
+    /**
+     * id
+     */
+    private Integer id;
+
+    /**
+     * 产品id
+     */
+    private Integer productId;
+
+    /**
+     * 营销时间
+     */
+    private String saleTime;
+
+    /**
+     * 营销地区
+     */
+    private String saleArea;
+
+    /**
+     * 销售量
+     */
+    private Double saleCount;
+
+    /**
+     * 销售额(万元)
+     */
+    private Double saleMoney;
+
+    /**
+     * 自定义许可费率
+     */
+    private Double customLicenseRate;
+
+    private String createName;
+
+    private String createId;
+
+    private Date createTime;
+}

+ 89 - 0
src/main/java/cn/cslg/pas/controller/ProductMarketDataController.java

@@ -0,0 +1,89 @@
+package cn.cslg.pas.controller;
+
+import cn.cslg.pas.common.core.base.Constants;
+import cn.cslg.pas.common.dto.business.ProductCategoryDTO;
+import cn.cslg.pas.common.dto.business.ProductMarketDataDTO;
+import cn.cslg.pas.common.dto.business.UpdateProductCategoryDTO;
+import cn.cslg.pas.common.dto.business.UpdateProductMarketDataDTO;
+import cn.cslg.pas.common.model.cronModel.Records;
+import cn.cslg.pas.common.model.request.StringRequest;
+import cn.cslg.pas.common.utils.Response;
+import cn.cslg.pas.exception.ConditionException;
+import cn.cslg.pas.exception.UnLoginException;
+import cn.cslg.pas.exception.XiaoShiException;
+import cn.cslg.pas.factorys.businessFactory.Business;
+import cn.cslg.pas.factorys.businessFactory.BusinessFactory;
+import com.alibaba.fastjson.JSONObject;
+import io.swagger.v3.oas.annotations.Operation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * 产品营销数据的controller层
+ * @Author xiexiang
+ * @Date 2023/11/16
+ */
+@Slf4j
+@RequestMapping(Constants.API_XiaoSHI + "/productMarketData")
+@RestController
+public class ProductMarketDataController {
+    @Autowired
+    private BusinessFactory businessFactory;
+
+    @Operation(summary = "查询产品营销数据")
+    @PostMapping("/queryProductMarketData")
+    public Response queryProductMarketData(@RequestBody StringRequest stringRequest) throws Exception {
+        Business business = businessFactory.getClass("productMarketDataService");
+        Records records = (Records) business.queryMessage(stringRequest);
+        return Response.success(records);
+    }
+
+    @Operation(summary = "添加产品营销数据")
+    @PostMapping("/addProductMarketData")
+    public Response addProductMarketData(@RequestBody ProductMarketDataDTO productMarketDataDTO) throws Exception {
+        Business business = businessFactory.getClass("productMarketDataService");
+        Integer id = null;
+        try {
+            id = (Integer) business.addMessage(productMarketDataDTO);
+        } catch (Exception e){
+            if(e instanceof XiaoShiException) {
+                return Response.error(e.getMessage());
+            } else if (e instanceof UnLoginException) {
+                return Response.unLogin(e.getMessage());
+            } else if (e instanceof ConditionException) {
+                return Response.conditionError(e.getMessage());
+            }
+        }
+        return Response.success(id);
+    }
+
+    @Operation(summary = "更新产品营销数据")
+    @PostMapping("/updateProductMarketData")
+    public Response updateProductMarketData(@RequestBody UpdateProductMarketDataDTO updateProductMarketDataDTO) throws Exception {
+        if (updateProductMarketDataDTO != null) {
+            Business business = businessFactory.getClass("productMarketDataService");
+            Integer id = (Integer) business.updateMessage(updateProductMarketDataDTO);
+            return Response.success(id);
+        } else {
+            return Response.error("网络异常");
+        }
+    }
+
+    @Operation(summary = "删除产品营销数据")
+    @PostMapping("/deleteReportProject")
+    public String deleteProductMarketData(@RequestBody List<Integer> ids) throws Exception {
+        if (ids != null && ids.size() != 0) {
+            Business business = businessFactory.getClass("productMarketDataService");
+            business.deleteMessage(ids);
+            return Response.success();
+        } else {
+            throw new XiaoShiException("需要删除的ids不能为空!");
+        }
+    }
+}

+ 65 - 0
src/main/java/cn/cslg/pas/domain/business/ProductMarketData.java

@@ -0,0 +1,65 @@
+package cn.cslg.pas.domain.business;
+
+import cn.cslg.pas.domain.BaseEntity;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 产品营销数据
+ * @Author xiexiang
+ * @Date 2023/11/16
+ */
+@Data
+@TableName("product_market_data")
+public class ProductMarketData extends BaseEntity<ProductMarketData> {
+    /**
+     * 产品id
+     */
+    @TableField(value = "product_id")
+    private Integer productId;
+
+    /**
+     * 营销时间
+     */
+    @TableField(value = "sale_time")
+    private String saleTime;
+
+    /**
+     * 营销地区
+     */
+    @TableField(value = "sale_area")
+    private String saleArea;
+
+    /**
+     * 销售量
+     */
+    @TableField(value = "sale_count")
+    private double saleCount;
+
+    /**
+     * 销售额(万元)
+     */
+    @TableField(value = "sale_money")
+    private double saleMoney;
+
+    /**
+     * 自定义许可费率
+     */
+    @TableField(value = "custom_license_rate")
+    private double customLicenseRate;
+
+    /**
+     * 创建人
+     */
+    @TableField(value = "create_id")
+    private String createId;
+    /**
+     * 创建时间
+     */
+    @TableField(value = "create_time")
+    private Date createTime;
+
+}

+ 19 - 0
src/main/java/cn/cslg/pas/mapper/ProductMarketDataMapper.java

@@ -0,0 +1,19 @@
+package cn.cslg.pas.mapper;
+
+import cn.cslg.pas.common.vo.business.ProductMarketDataVO;
+import cn.cslg.pas.domain.business.ProductMarketData;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * 产品营销数据的Mapper层
+ * @Author xiexiang
+ * @Date 2023/11/16
+ */
+@Repository
+public interface ProductMarketDataMapper extends BaseMapper<ProductMarketData> {
+    public List<ProductMarketDataVO> getProductMarketData(String sql1, String sql2, String sql3);
+    public Long getProductCategoryCount(String sql);
+}

+ 175 - 0
src/main/java/cn/cslg/pas/service/business/ProductMarketDataService.java

@@ -0,0 +1,175 @@
+package cn.cslg.pas.service.business;
+
+import cn.cslg.pas.common.dto.business.ProductMarketDataDTO;
+import cn.cslg.pas.common.dto.business.UpdateProductMarketDataDTO;
+import cn.cslg.pas.common.model.cronModel.Personnel;
+import cn.cslg.pas.common.model.cronModel.PersonnelVO;
+import cn.cslg.pas.common.model.cronModel.Records;
+import cn.cslg.pas.common.model.request.GroupRequest;
+import cn.cslg.pas.common.model.request.QueryRequest;
+import cn.cslg.pas.common.utils.CacheUtils;
+import cn.cslg.pas.common.utils.LoginUtils;
+import cn.cslg.pas.common.vo.business.CustomFieldVO;
+import cn.cslg.pas.common.vo.business.ProductMarketDataVO;
+import cn.cslg.pas.domain.business.ProductMarketData;
+import cn.cslg.pas.exception.UnLoginException;
+import cn.cslg.pas.exception.XiaoShiException;
+import cn.cslg.pas.factorys.businessFactory.Business;
+import cn.cslg.pas.mapper.ProductMarketDataMapper;
+import cn.cslg.pas.service.permissions.PermissionService;
+import cn.cslg.pas.service.query.FormatQueryService;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+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.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Author xiexiang
+ * @Date 2023/11/16
+ */
+@Service
+@Slf4j
+public class ProductMarketDataService extends ServiceImpl<ProductMarketDataMapper, ProductMarketData> implements Business {
+    @Autowired
+    private FormatQueryService formatQueryService;
+
+    @Autowired
+    private ProductMarketDataMapper productMarketDataMapper;
+
+    @Autowired
+    private CacheUtils cacheUtils;
+
+    @Autowired
+    private LoginUtils loginUtils;
+
+    @Autowired
+    private PermissionService permissionService;
+
+    @Override
+    public Object queryMessage(QueryRequest queryRequest) throws Exception {
+        List<String> sqls = formatQueryService.reSqls(queryRequest,"productMarketData");
+        List<ProductMarketDataVO> productMarketDataVOS = productMarketDataMapper.getProductMarketData(sqls.get(0),sqls.get(1),sqls.get(2));
+        //查询总数
+        Long total = productMarketDataMapper.getProductCategoryCount(sqls.get(0));
+        this.loadProductMarketData(productMarketDataVOS);
+        Records records = new Records();
+        records.setCurrent(queryRequest.getCurrent());
+        records.setSize(queryRequest.getSize());
+        records.setData(productMarketDataVOS);
+        records.setTotal(total);
+        return records;
+    }
+
+    @Override
+    public Object addMessage(Object object, List<MultipartFile> files) {
+        return null;
+    }
+
+    @Override
+    public Object deleteMessage(List<Integer> ids) throws IOException {
+        if (ids != null && ids.size() != 0) {
+            this.removeBatchByIds(ids);
+            return ids;
+        } else {
+            throw new XiaoShiException("需要删除的ids不能为空");
+        }
+    }
+
+    @Override
+    public Object updateMessage(Object object, List<MultipartFile> files) {
+        return null;
+    }
+
+    @Override
+    public Object getGroup(GroupRequest groupRequest, String tableName) throws Exception {
+        return null;
+    }
+
+    @Override
+    public Object addMessage(Object object) {
+        //判断参数不为空
+        if (object.equals(null)) {
+            throw new XiaoShiException("传入参数不能为空!");
+        }
+        //object to productMarketDataDTO
+        ProductMarketDataDTO productMarketDataDTO = (ProductMarketDataDTO) object;
+        Integer productId = productMarketDataDTO.getProductId();
+        //判断产品id不能为空
+        if (productId.equals(null)) {
+            throw new XiaoShiException("产品id不能为空!");
+        }
+        ProductMarketData productMarketData = new ProductMarketData();
+        BeanUtils.copyProperties(productMarketDataDTO, productMarketData);
+        //获取登录人信息
+        PersonnelVO personnelVO = new PersonnelVO();
+        try {
+            personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
+        } catch (Exception e) {
+            throw new UnLoginException("未登录");
+        }
+        productMarketData.setCreateId(personnelVO.getId());
+        //数据入表
+        productMarketData.insert();
+        //返回营销数据id
+        return productMarketData.getId();
+    }
+
+    @Override
+    public Object updateMessage(Object object) {
+        //判断参数不为空
+        if (object.equals(null)) {
+            throw new XiaoShiException("传入参数不能为空!");
+        }
+        //object to updateProductMarketDataDTO
+        UpdateProductMarketDataDTO updateProductMarketDataDTO = (UpdateProductMarketDataDTO) object;
+        Integer productId = updateProductMarketDataDTO.getProductId();
+        if (productId.equals(null)) {
+            throw new XiaoShiException("产品id不能为空!");
+        }
+        ProductMarketData productMarketData = this.getById(updateProductMarketDataDTO.getId());
+        BeanUtils.copyProperties(updateProductMarketDataDTO, productMarketData);
+        //数据入表
+        productMarketData.updateById();
+        //返回营销数据id
+        return productMarketData.getId();
+    }
+
+
+    /**
+     * 装载产品营销数据
+     * @param productMarketDataVOS
+     */
+    private void loadProductMarketData(List<ProductMarketDataVO> productMarketDataVOS) throws IOException {
+        List<String> createIds = new ArrayList<>();
+        productMarketDataVOS.forEach(
+                item -> {
+                    if (item.getCreateId() != null) {
+                        createIds.add(item.getCreateId());
+                    }
+                }
+        );
+        List<Personnel> personnels = new ArrayList<>();
+        //查询创建人名称
+        if (createIds.size() != 0) {
+            String res = permissionService.getPersonnelByIdsFromPCS(createIds);
+            JSONObject jsonObject = JSONObject.parseObject(res);
+            personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
+        }
+        for (ProductMarketDataVO productMarketDataVO : productMarketDataVOS) {
+            //装载人员信息
+            Personnel personnel = personnels.stream().filter(item -> item.getId().equals(productMarketDataVO.getCreateId())).findFirst().orElse(null);
+            if (personnel != null) {
+                productMarketDataVO.setCreateName(personnel.getPersonnelName());
+            } else {
+                throw new XiaoShiException("未获取到当前登陆人信息");
+            }
+        }
+    }
+}

+ 108 - 0
src/main/resources/jsons/productMarketData.json

@@ -0,0 +1,108 @@
+[
+  {"name":"Id",
+    "type":"Integer",
+    "value":"id",
+    "field":"id",
+    "sqlField": "id",
+    "sqlClass": "getComSql",
+    "orderClass": "",
+    "groupClass":"",
+    "ifSearch":"false",
+    "ifGroup": "false",
+    "ifShow":"false"
+  },
+  {"name":"产品Id",
+    "type":"Integer",
+    "value":"product_id",
+    "field":"product_id",
+    "sqlField": "productId",
+    "sqlClass": "getComSql",
+    "orderClass": "",
+    "groupClass":"",
+    "ifSearch":"false",
+    "ifGroup": "false",
+    "ifShow":"true"
+  },
+  {"name":"营销时间",
+    "type":"DateTime",
+    "value":"saleTime",
+    "field": "saleTime",
+    "sqlField": "sale_time",
+    "sqlClass": "",
+    "orderClass": "",
+    "groupClass":"",
+    "ifSearch":"false",
+    "ifGroup": "false",
+    "ifShow":"true"
+  },
+  {"name":"营销地区",
+    "type":"String",
+    "value":"saleArea",
+    "field": "saleArea",
+    "sqlField": "sale_area",
+    "sqlClass": "",
+    "orderClass": "getComOrder",
+    "groupClass":"",
+    "ifSearch":"false",
+    "ifGroup": "false",
+    "ifShow":"true"
+  },
+  {"name":"销售量",
+    "type":"Double",
+    "value":"saleCount",
+    "field": "saleCount",
+    "sqlField": "sale_count",
+    "sqlClass": "",
+    "orderClass": "getComOrder",
+    "groupClass":"",
+    "ifSearch":"false",
+    "ifGroup": "false",
+    "ifShow":"true"
+  },
+  {"name":"销售额(万元)",
+    "type":"Double",
+    "value":"saleMoney",
+    "field": "saleMoney",
+    "sqlField": "sale_money",
+    "sqlClass": "",
+    "orderClass": "getComOrder",
+    "ifSearch":"false",
+    "ifGroup": "false",
+    "ifShow":"true"
+  },
+  {"name":"自定义许可费率",
+    "type":"Double",
+    "value":"customLicenseRate",
+    "field": "customLicenseRate",
+    "sqlField": "custom_license_rate",
+    "sqlClass": "",
+    "orderClass": "getComOrder",
+    "ifSearch":"false",
+    "ifGroup": "false",
+    "ifShow":"true"
+  },
+  {"name":"创建人",
+  "type":"String",
+  "value":"createName",
+  "field": "createName",
+  "sqlField": "create_id",
+  "sqlClass": "getCreateNameSql",
+  "orderClass": "getCreateNameOrder",
+  "groupClass":"getComGroup",
+  "ifSearch":"true",
+  "ifGroup": "false",
+  "ifShow":"true"
+},
+  {"name":"创建时间",
+    "type":"DateTime",
+    "value":"createTime",
+    "field": "createTime",
+    "sqlField": "create_time",
+    "sqlClass": "getDateTimeSql",
+    "orderClass": "getComOrder",
+    "groupClass":"getTimeGroup",
+    "ifSearch":"true",
+    "ifGroup": "false",
+    "ifShow":"true"
+  }
+]

+ 42 - 0
src/main/resources/mapper/ProductMarketDataMapper.xml

@@ -0,0 +1,42 @@
+<?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="cn.cslg.pas.mapper.ProductMarketDataMapper">
+    <!--namespace根据自己需要创建的的mapper的路径和名称填写-->
+    <select id="getProductMarketData" resultType="cn.cslg.pas.common.vo.business.ProductMarketDataVO">
+        select id, product_id as productId, sale_time as saleTime, sale_area as saleArea, sale_count as saleCount,
+               sale_money as saleMoney, custom_license_rate as customLicenseRate, create_id as createId,create_time as createTime from product_market_data
+        <if test="sql1!=''">
+
+            where ${sql1}
+        </if>
+
+
+        ${sql2} ${sql3}
+    </select>
+
+    <select id="getProductCategoryCount" resultType="java.lang.Long">
+       select count(*) from product_market_data
+        <if test="sql!=''">
+
+            where ${sql}
+        </if>
+        ) as c
+    </select>
+
+    <select id="getGroups" resultType="java.lang.String">
+        select ${selectField} from ${tableName}
+        <if test="sqls.get(0)!=''">
+            where ${sqls.get(0)}
+        </if>
+        group by ${groupField} ${sqls.get(1)} ${sqls.get(2)}
+    </select>
+
+    <select id="getGroupsCount" resultType="java.lang.Long">
+        select count(*) from (select ${selectField} from ${tableName}
+        <if test="sqls.get(0)!=''">
+            where ${sqls.get(0)}
+        </if>
+        group by ${groupField}
+        ) as c
+    </select>
+</mapper>

+ 35 - 0
src/test/java/cn/cslg/pas/service/ProductMarketDataServiceTests.java

@@ -0,0 +1,35 @@
+package cn.cslg.pas.service;
+
+import cn.cslg.pas.common.dto.business.ProductMarketDataDTO;
+import cn.cslg.pas.common.utils.Response;
+import cn.cslg.pas.controller.ProductMarketDataController;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * @Author xiexiang
+ * @Date 2023/11/16
+ */
+@SpringBootTest
+public class ProductMarketDataServiceTests {
+    @Autowired
+    private ProductMarketDataController productMarketDataController;
+
+    @Test
+    public void addProductMarketData() throws Exception {
+        ProductMarketDataDTO productMarketDataDTO = new ProductMarketDataDTO();
+        productMarketDataDTO.setProductId(10);
+        productMarketDataDTO.setSaleArea("昆山");
+        productMarketDataDTO.setSaleTime("2023-11-11");
+        productMarketDataDTO.setSaleCount(10.0);
+        productMarketDataDTO.setSaleMoney(13.4);
+        productMarketDataDTO.setCustomLicenseRate(0.1);
+        Response response = productMarketDataController.addProductMarketData(productMarketDataDTO);
+        Assert.assertEquals(200,Integer.parseInt(response.getCode().toString()));
+    }
+}