|
@@ -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("未获取到当前登陆人信息");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|