|
@@ -1,25 +1,32 @@
|
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
-import com.management.platform.entity.ActionLog;
|
|
|
-import com.management.platform.entity.BusinessOpportunity;
|
|
|
-import com.management.platform.entity.Clue;
|
|
|
-import com.management.platform.entity.User;
|
|
|
-import com.management.platform.mapper.ActionLogMapper;
|
|
|
-import com.management.platform.mapper.BusinessOpportunityMapper;
|
|
|
+import com.management.platform.entity.*;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.BusinessOpportunityService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.service.WxCorpInfoService;
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 服务实现类
|
|
|
+ * 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author Seyason
|
|
@@ -28,10 +35,25 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportunityMapper, BusinessOpportunity> implements BusinessOpportunityService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ExcelExportServiceImpl excelExportService;
|
|
|
+ @Resource
|
|
|
+ private WxCorpInfoService wxCorpInfoService;
|
|
|
@Resource
|
|
|
private BusinessOpportunityMapper bOMapper;
|
|
|
@Resource
|
|
|
+ private TaskMapper taskMapper;
|
|
|
+ @Resource
|
|
|
private ActionLogMapper actionLogMapper;
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ private BusinessItemProductMapper biMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysFormMapper sysFormMapper;
|
|
|
+ @Autowired
|
|
|
+ private UploadFileMapper uploadFileMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public List<BusinessOpportunity> getAll(BusinessOpportunity bo) {
|
|
|
return bOMapper.selectAllList(bo);
|
|
@@ -39,12 +61,39 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
|
|
|
@Override
|
|
|
public List<BusinessOpportunity> getAll1(BusinessOpportunity bo, User user) {
|
|
|
- return bOMapper.selectAllList1(bo,user.getId());
|
|
|
+ return bOMapper.selectAllList1(bo, user.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BusinessOpportunity getInfo(BusinessOpportunity bo, User user) {
|
|
|
+ BusinessOpportunity businessOpportunity = bOMapper.selectById(bo.getId());
|
|
|
+ businessOpportunity.setActionLogList(actionLogMapper.selectList(new QueryWrapper<ActionLog>().eq("item_id", bo.getId()).eq("code", "business")));
|
|
|
+ businessOpportunity.setUploadFilePList(uploadFileMapper.selectByInfoList("business",bo.getId()));
|
|
|
+ businessOpportunity.setTaskList(taskMapper.selectList(new QueryWrapper<Task>().eq("business_opportunity_id",bo.getId())));
|
|
|
+ List<BusinessItemProduct> businessItemProducts = biMapper.selectListToBoId(bo.getId());
|
|
|
+ businessOpportunity.setBusinessItemProductList(businessItemProducts);
|
|
|
+ if (businessItemProducts.size() > 0){
|
|
|
+ BigDecimal finalPrice = new BigDecimal(0);
|
|
|
+ BigDecimal discountedPrice = new BigDecimal(0);
|
|
|
+ for (BusinessItemProduct businessItemProduct : businessItemProducts) {
|
|
|
+ BigDecimal price = businessItemProduct.getPrice();
|
|
|
+ // 原价
|
|
|
+ finalPrice = finalPrice.add(price.multiply(new BigDecimal(businessItemProduct.getQuantity())));
|
|
|
+ //折扣率
|
|
|
+ BigDecimal divide = new BigDecimal(businessItemProduct.getDiscount()).divide(new BigDecimal(100));
|
|
|
+ // 折后价格
|
|
|
+ discountedPrice = discountedPrice.add(price.multiply(divide));
|
|
|
+ }
|
|
|
+ BigDecimal divide = discountedPrice.divide(finalPrice);
|
|
|
+ // 整单折扣率
|
|
|
+ businessOpportunity.setFinalPrice(divide.multiply(new BigDecimal(100)));
|
|
|
+ }
|
|
|
+ return businessOpportunity;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<BusinessOpportunity> getAll2(BusinessOpportunity bo, User user) {
|
|
|
- return bOMapper.selectAllList2(bo,user.getId());
|
|
|
+ return bOMapper.selectAllList2(bo, user.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -54,23 +103,31 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
|
|
|
@Override
|
|
|
public int getTotal1(BusinessOpportunity bo, User user) {
|
|
|
- return bOMapper.getTotal1(bo,user.getId());
|
|
|
+ return bOMapper.getTotal1(bo, user.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int getTotal2(BusinessOpportunity bo, User user) {
|
|
|
- return bOMapper.getTotal2(bo,user.getId());
|
|
|
+ return bOMapper.getTotal2(bo, user.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void insert(BusinessOpportunity bo) {
|
|
|
+ setNull(bo);
|
|
|
bo.setCreateTime(new Date());
|
|
|
bOMapper.insert(bo);
|
|
|
-
|
|
|
+ ActionLog actionLog = new ActionLog();
|
|
|
+ actionLog.setUserId(bo.getUserId());
|
|
|
+ actionLog.setItemId(bo.getId());
|
|
|
+ actionLog.setCode("business");
|
|
|
+ actionLog.setName("创建了线索");
|
|
|
+ actionLogMapper.insert(actionLog);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void update(BusinessOpportunity bo,String userId) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void update(BusinessOpportunity bo, String userId) {
|
|
|
setNull(bo);
|
|
|
bOMapper.updateById(bo);
|
|
|
ActionLog log = new ActionLog();
|
|
@@ -83,6 +140,7 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void getAndTransfer(BusinessOpportunity bo, User user) {
|
|
|
UpdateWrapper<BusinessOpportunity> updateWrapper = new UpdateWrapper<>();
|
|
|
String ids1 = bo.getIds();
|
|
@@ -116,9 +174,56 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- updateWrapper.set("incharger_id",inchargerId);
|
|
|
+ updateWrapper.set("incharger_id", inchargerId);
|
|
|
bOMapper.update(null, updateWrapper);
|
|
|
}
|
|
|
+
|
|
|
+ @Value(value = "${upload.file}")
|
|
|
+ private String path;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object exportData(BusinessOpportunity bo, HttpServletRequest request) throws Exception {
|
|
|
+ User user = userMapper.selectById(request.getHeader("token"));
|
|
|
+ SysForm sysForm = sysFormMapper.selectOne(new LambdaQueryWrapper<SysForm>().eq(SysForm::getCompanyId, user.getCompanyId()).eq(SysForm::getCode, "Clue").eq(SysForm::getIsCurrent, 1));
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, user.getCompanyId()));
|
|
|
+ String config = sysForm.getConfig();
|
|
|
+ JSONObject configOb = JSON.parseObject(config);
|
|
|
+ JSONArray configObJSONArray = configOb.getJSONArray("list");
|
|
|
+ List<List<String>> dataList = new ArrayList<>();
|
|
|
+ List<String> titleList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < configObJSONArray.size(); i++) {
|
|
|
+ JSONObject item = configObJSONArray.getJSONObject(i);
|
|
|
+ titleList.add(item.getString("label"));
|
|
|
+ }
|
|
|
+ dataList.add(titleList);//设置表头
|
|
|
+
|
|
|
+
|
|
|
+ bo.setCompanyId(user.getCompanyId());
|
|
|
+
|
|
|
+ String fileName = "商机表导出_" + System.currentTimeMillis();
|
|
|
+ return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo, fileName, dataList, path);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public HttpRespMsg saveProduct(BusinessOpportunity bo, User user) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ msg.setMsg("操作成功");
|
|
|
+ biMapper.delete(new QueryWrapper<BusinessItemProduct>().eq("business_id",bo.getId()));
|
|
|
+ List<BusinessItemProduct> businessItemProductList = bo.getBusinessItemProductList();
|
|
|
+// biMapper.saveBatch()
|
|
|
+ for (BusinessItemProduct businessItemProduct : businessItemProductList) {
|
|
|
+ biMapper.insert(businessItemProduct);
|
|
|
+ }
|
|
|
+ ActionLog al = new ActionLog();
|
|
|
+ al.setCode("business");
|
|
|
+ al.setName("编辑了产品");
|
|
|
+ al.setUserId(user.getId());
|
|
|
+ al.setItemId(bo.getId());
|
|
|
+ actionLogMapper.insert(al);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
private BusinessOpportunity setNull(BusinessOpportunity bo) {
|
|
|
if (bo.getPlate1() == "") {
|
|
|
bo.setPlate1(null);
|