|
|
@@ -0,0 +1,380 @@
|
|
|
+package com.goafanti.user.service.impl;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import com.goafanti.common.bo.CityBo;
|
|
|
+import com.goafanti.common.bo.Error;
|
|
|
+import com.goafanti.common.bo.ProvinceBo;
|
|
|
+import com.goafanti.common.dao.DistrictGlossoryMapper;
|
|
|
+import com.goafanti.common.dao.OrganizationContactBookMapper;
|
|
|
+import com.goafanti.common.dao.OrganizationIdentityMapper;
|
|
|
+import com.goafanti.common.dao.UserCareerMapper;
|
|
|
+import com.goafanti.common.dao.UserChannelMapper;
|
|
|
+import com.goafanti.common.dao.UserMapper;
|
|
|
+import com.goafanti.common.dao.UserTransferLogMapper;
|
|
|
+import com.goafanti.common.enums.SocietyTag;
|
|
|
+import com.goafanti.common.error.BusinessException;
|
|
|
+import com.goafanti.common.model.User;
|
|
|
+import com.goafanti.common.utils.ExcelUtils;
|
|
|
+import com.goafanti.common.utils.PasswordUtil;
|
|
|
+import com.goafanti.core.mybatis.BaseMybatisDao;
|
|
|
+import com.goafanti.core.shiro.token.TokenManager;
|
|
|
+import com.goafanti.user.bo.InputUserChannel;
|
|
|
+import com.goafanti.user.bo.OutUserChannel;
|
|
|
+import com.goafanti.user.service.UserChannelService;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class UserChannelServiceImpl extends BaseMybatisDao<UserCareerMapper> implements UserChannelService{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserMapper userMapper;
|
|
|
+ @Autowired
|
|
|
+ private OrganizationIdentityMapper organizationIdentityMapper;
|
|
|
+ @Autowired
|
|
|
+ private OrganizationContactBookMapper organizationContactBookMapper;
|
|
|
+ @Autowired
|
|
|
+ private DistrictGlossoryMapper districtGlossoryMapper;
|
|
|
+ @Autowired
|
|
|
+ private UserTransferLogMapper userTransferLogMapper;
|
|
|
+ @Autowired
|
|
|
+ private UserChannelMapper userChannelMapper;
|
|
|
+ @Resource(name = "passwordUtil")
|
|
|
+ private PasswordUtil passwordUtil;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object add(InputUserChannel in) {
|
|
|
+ String uid=UUID.randomUUID().toString();
|
|
|
+ Calendar now = Calendar.getInstance();
|
|
|
+ now.set(Calendar.MILLISECOND, 0);
|
|
|
+ in.setAid(TokenManager.getAdminId());
|
|
|
+ in.setStatus(0);
|
|
|
+ in.setUid(uid);
|
|
|
+ User u=new User();
|
|
|
+ u.setId(uid);
|
|
|
+ u.setNickname(in.getUserName());
|
|
|
+ u.setCreateTime(now.getTime());
|
|
|
+ u.setPassword(passwordUtil.getEncryptPwd("123456", now.getTime()));
|
|
|
+ userChannelMapper.insertSelective(in);
|
|
|
+ userMapper.insertSelective(u);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int batchImport() {
|
|
|
+// List<TemporaryReceivables> list=userChannelMapper.selectByaid(TokenManager.getAdminId());
|
|
|
+// if(list.size()>99)throw new BusinessException(new Error("数量过大,建议不超过99。"));
|
|
|
+// List<TOrderBillNew> listBull=new ArrayList<>();
|
|
|
+// for (TemporaryReceivables tr : list) {
|
|
|
+// TOrderBillNew tbn=new TOrderBillNew();
|
|
|
+// //获取已收款
|
|
|
+// BigDecimal bill = tOrderBillNewMapper.getAmountByOid(tr.getOrderNo());
|
|
|
+// //获取总金额
|
|
|
+// TOrderNewBo t=tOrderNewMapper.getOrderNewDetail(tr.getOrderNo());
|
|
|
+// //订单匹配不到
|
|
|
+// if(t==null||t.getOrderNo()==null) {
|
|
|
+// tr.setStatus(ReceivablesStatus.DDYC.getCode());
|
|
|
+// temporaryReceivablesMapper.updateByPrimaryKeySelective(tr);
|
|
|
+// continue;
|
|
|
+// }else if(t.getDeleteSign()==2||t.getDeleteSign()==3) {
|
|
|
+// tr.setStatus(ReceivablesStatus.BGSD.getCode());
|
|
|
+// temporaryReceivablesMapper.updateByPrimaryKeySelective(tr);
|
|
|
+// continue;
|
|
|
+// }else if(!tr.getCorporateName().equals(t.getUserName())) {
|
|
|
+// tr.setStatus(ReceivablesStatus.MCYC.getCode());
|
|
|
+// temporaryReceivablesMapper.updateByPrimaryKeySelective(tr);
|
|
|
+// continue;
|
|
|
+// }else if(temporaryReceivablesMapper.selectReceivablesNumberRepeats(tr)>0) {
|
|
|
+// tr.setStatus(ReceivablesStatus.YSK.getCode());
|
|
|
+// temporaryReceivablesMapper.updateByPrimaryKeySelective(tr);
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// //计算收款结果
|
|
|
+// BigDecimal bd = bill.add(tr.getAmount());
|
|
|
+// //判断表中数据
|
|
|
+// BigDecimal count = new BigDecimal(0).add(bd);
|
|
|
+// for (TOrderBillNew tBill : listBull) {
|
|
|
+// if (tBill.getOrderNo().equals(tr.getOrderNo())) {
|
|
|
+// count=count.add(tBill.getTransactionAmount());
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// TOrderBonus bonus = new TOrderBonus();
|
|
|
+// bonus.setId(UUID.randomUUID().toString());
|
|
|
+// bonus.setOrderNo(tr.getOrderNo());
|
|
|
+// bonus.setGrantBy(TokenManager.getAdminId());
|
|
|
+// int lstaus = 0;//如果订单流水小于首付 lstaus 0
|
|
|
+// if(count.compareTo(t.getTotalAmount()) == 1){//如果订单流水总额大于总金额 return -1
|
|
|
+// tr.setStatus(ReceivablesStatus.JEYC.getCode());
|
|
|
+// temporaryReceivablesMapper.updateByPrimaryKeySelective(tr);
|
|
|
+// continue;
|
|
|
+// }else if (count.compareTo(t.getTotalAmount()) == 0) {//等于总额
|
|
|
+// //付完款//如果订单流水等于于总金额 lstaus 2
|
|
|
+// lstaus = 2;
|
|
|
+// bonus.setBonusSubject(BonusSubject.WK.getCode());//12
|
|
|
+// //发放给技术员如果付完款所有参与这个项目任务的人都会有结算奖
|
|
|
+// //获得所有的任务负责人
|
|
|
+// List<TOrderTask> l = tOrderTaskMapper.getReceiverByOid(tr.getOrderNo());
|
|
|
+// for (TOrderTask tOrderTask : l) {
|
|
|
+// if(null != tOrderTask &&null != tOrderTask.getTaskReceiver()){
|
|
|
+// bonus.setTaskId(tOrderTask.getId());//任务id
|
|
|
+// bonus.setGrantTarget(tOrderTask.getTaskReceiver());
|
|
|
+// bonus.setGrantType(1);
|
|
|
+// int c = tOrderBonusMapper.checkByOnoAndSub(bonus);
|
|
|
+// //不存在就设置
|
|
|
+// if(c==0){
|
|
|
+// bonus.setId(UUID.randomUUID().toString());
|
|
|
+// tOrderBonusMapper.insertSelective(bonus);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if(tr.getStatus()==2) {
|
|
|
+// tr.setStatus(0);
|
|
|
+// temporaryReceivablesMapper.updateByPrimaryKeySelective(tr);
|
|
|
+// }
|
|
|
+// addOrderLog(tr.getOrderNo(), OrderLogProcess.CWQK.getCode());
|
|
|
+// }else if (count.compareTo(t.getTotalAmount()) == -1) {//小于总额
|
|
|
+// //如果订单流水小于总金额
|
|
|
+// if(bd.compareTo(t.getFirstAmount()) == 0 || bd.compareTo(t.getFirstAmount()) == 1){//首付完成
|
|
|
+// //查看首付奖是否存在
|
|
|
+// TOrderBonus b = new TOrderBonus();
|
|
|
+// b.setOrderNo(tr.getOrderNo());
|
|
|
+// b.setBonusSubject(11);
|
|
|
+// b.setGrantType(0);
|
|
|
+// b.setGrantTarget(t.getSalesmanId());
|
|
|
+// int c = tOrderBonusMapper.checkByOnoAndSub(b);
|
|
|
+// //不存在就设置
|
|
|
+// if(c==0){
|
|
|
+// bonus.setBonusSubject(BonusSubject.SF.getCode());//11
|
|
|
+// }
|
|
|
+// lstaus = 1;
|
|
|
+//
|
|
|
+// addOrderLog(tr.getOrderNo(), OrderLogProcess.CWSF.getCode());
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// if(tr.getStatus()==2) {
|
|
|
+// tr.setStatus(0);
|
|
|
+// temporaryReceivablesMapper.updateByPrimaryKeySelective(tr);
|
|
|
+// }
|
|
|
+// //否则新增流水信息
|
|
|
+// Date date=new Date();
|
|
|
+// tbn.setBillNo(UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
+// tbn.setCreater(TokenManager.getAdminId());
|
|
|
+// tbn.setType(1);//批量
|
|
|
+// tbn.setOrderNo(t.getOrderNo());
|
|
|
+// tbn.setCreateTime(date);
|
|
|
+// tbn.setPayeeId("0");//默认设置0
|
|
|
+// tbn.setPayerId(t.getBuyerId());
|
|
|
+// tbn.setTransactionSubject(0);
|
|
|
+// tbn.setTransactionChannel(2);
|
|
|
+// tbn.setConfirmSign(0);
|
|
|
+// tbn.setTransactionAmount(tr.getAmount());
|
|
|
+// tbn.setDeleteSign((new Byte("0")));
|
|
|
+// tbn.setFinancialPayTime(tr.getReceivablesTime());
|
|
|
+// tbn.setFinancialPayNo(tr.getFinancialPayNo());
|
|
|
+// tbn.setRemarks(tr.getRemarks());
|
|
|
+// tOrderMidMapper.updatefinalReceivables(t.getOrderNo(),tr.getAmount(),date);
|
|
|
+// //修改订单结算金额和结算状态
|
|
|
+// //如果已经首付并且流程状态是没有派给咨询师的修改流程状态为4
|
|
|
+// TOrderNew orderNew = new TOrderNew();
|
|
|
+// orderNew.setOrderNo(tr.getOrderNo());
|
|
|
+// //这里的已收金额是以前收的所有金额加上本次收的金额
|
|
|
+// orderNew.setSettlementAmount(count);
|
|
|
+// orderNew.setLiquidationStatus(lstaus);
|
|
|
+// tOrderNewMapper.updateByPrimaryKeySelective(orderNew);
|
|
|
+// //如果达到奖金发放要求新增奖金信息
|
|
|
+// if(null != bonus.getBonusSubject()){
|
|
|
+// bonus.setId(UUID.randomUUID().toString());
|
|
|
+// bonus.setGrantTarget(t.getSalesmanId());
|
|
|
+// //设置发放人类型
|
|
|
+// bonus.setGrantType(0);
|
|
|
+// tOrderBonusMapper.insertSelective(bonus);
|
|
|
+// }
|
|
|
+//
|
|
|
+// listBull.add(tbn);
|
|
|
+// }
|
|
|
+// if(!listBull.isEmpty()) {
|
|
|
+// tOrderBillNewMapper.insertBatch(listBull);
|
|
|
+// temporaryReceivablesMapper.deleteNormalByaid(TokenManager.getAdminId());
|
|
|
+// }else {
|
|
|
+// return -1;
|
|
|
+// }
|
|
|
+// LoggerUtils.debug(getClass(), "=========================批量导入结束===================");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OutUserChannel> batchListReceivables(MultipartFile file) {
|
|
|
+ //获得Workbook工作薄对象
|
|
|
+ Workbook workbook = ExcelUtils.getWorkBook(file);
|
|
|
+ //创建一个对象,用来存储数据
|
|
|
+ List<InputUserChannel> list=new ArrayList<>();
|
|
|
+ List<InputUserChannel> list2=new ArrayList<>();
|
|
|
+ String aid=TokenManager.getAdminId();
|
|
|
+ Calendar now = Calendar.getInstance();
|
|
|
+ now.set(Calendar.MILLISECOND, 0);
|
|
|
+ if(workbook != null){
|
|
|
+ //获得当前sheet工作表
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ if(sheet == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获得当前sheet的开始行
|
|
|
+ int firstRowNum = sheet.getFirstRowNum();
|
|
|
+ //获得当前sheet的结束行
|
|
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
|
+ //处理空白行
|
|
|
+ for (int i = firstRowNum; i <= sheet.getLastRowNum();i++) {
|
|
|
+ Row r = sheet.getRow(i);
|
|
|
+ if(r == null){
|
|
|
+ // 如果是空行(即没有任何数据、格式),直接把它以下的数据往上移动
|
|
|
+ sheet.shiftRows(i+1, sheet.getLastRowNum(),-1);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ boolean flag = false;
|
|
|
+ for(Cell c:r){
|
|
|
+ if(c.getCellTypeEnum() != CellType.BLANK){
|
|
|
+ flag = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(flag){
|
|
|
+ i++;
|
|
|
+ continue;
|
|
|
+ } else{//如果是空白行(即可能没有数据,但是有一定格式)
|
|
|
+ if(i == sheet.getLastRowNum())//如果到了最后一行,直接将那一行remove掉
|
|
|
+ sheet.removeRow(r);
|
|
|
+ else//如果还没到最后一行,则数据往上移一行
|
|
|
+ sheet.shiftRows(i+1, sheet.getLastRowNum(),-1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lastRowNum=sheet.getLastRowNum();
|
|
|
+ if (lastRowNum<2) {
|
|
|
+ throw new BusinessException(new Error("未找到正确的参数。"));
|
|
|
+ }
|
|
|
+
|
|
|
+ //循环第2行后的所有行
|
|
|
+ for(int rowNum = firstRowNum+2;rowNum <= lastRowNum;rowNum++){
|
|
|
+ //获得当前行
|
|
|
+ Row row = sheet.getRow(rowNum);
|
|
|
+ if(row == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //获得当前行的开始列
|
|
|
+ int firstCellNum = row.getFirstCellNum();
|
|
|
+ //获得当前行的列数
|
|
|
+ int lastCellNum = row.getLastCellNum();
|
|
|
+ //循环当前行 cellNum = (firstCellNum+1) 则是除开第一例
|
|
|
+ InputUserChannel in=new InputUserChannel();
|
|
|
+
|
|
|
+ List<CityBo> cList=districtGlossoryMapper.getCity();
|
|
|
+ List<ProvinceBo>pList=districtGlossoryMapper.getProvince();
|
|
|
+ for(int cellNum = (firstCellNum); cellNum < lastCellNum;cellNum++){
|
|
|
+ Cell cell = row.getCell(cellNum);
|
|
|
+ try {
|
|
|
+ switch (cellNum) {
|
|
|
+ case 0:
|
|
|
+ in.setUserName(ExcelUtils.getCellValue(cell));
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ in.setProvince(getProvinceId(pList,ExcelUtils.getCellValue(cell)));
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ in.setCity(getCityId(cList,ExcelUtils.getCellValue(cell)));
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ in.setSocietyTag(SocietyTag.getCodeByValue(ExcelUtils.getCellValue(cell)).toString());
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ in.setContacts(ExcelUtils.getCellValue(cell));
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ in.setContactMobile(ExcelUtils.getCellValue(cell));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BusinessException(new Error("表格第"+(rowNum+1)+"行输入内容不正确。"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String uid=UUID.randomUUID().toString();
|
|
|
+ in.setAid(aid);
|
|
|
+ in.setCreateTime(now.getTime());
|
|
|
+ in.setShareType(3);
|
|
|
+ in.setPassword(passwordUtil.getEncryptPwd("123456", now.getTime()));
|
|
|
+ User u=userMapper.selectByName(in.getUserName());
|
|
|
+ if (u!=null) {
|
|
|
+ in.setStatus(1);
|
|
|
+ in.setUid(u.getId());
|
|
|
+ list2.add(in);
|
|
|
+ }else {
|
|
|
+ in.setStatus(0);
|
|
|
+ in.setUid(uid);
|
|
|
+ list.add(in);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (InputUserChannel in : list) {
|
|
|
+ int i=0;
|
|
|
+ for (InputUserChannel in2 : list) {
|
|
|
+ if (in.getUserName().equals(in2.getUserName())) {
|
|
|
+ i++;
|
|
|
+ if (i>1) {
|
|
|
+ throw new BusinessException(String.format("客户名称:%s 重复录入", in.getUserName()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ userMapper.insertBatch(list);
|
|
|
+ organizationIdentityMapper.insertBatch(list);
|
|
|
+ organizationContactBookMapper.insertBatch(list);
|
|
|
+ userChannelMapper.insertBatch(list);
|
|
|
+ userTransferLogMapper.insertBatch(list);
|
|
|
+ }
|
|
|
+ if(!list2.isEmpty())userChannelMapper.insertBatch(list2);
|
|
|
+ return userChannelMapper.selectByAidAndstatus(aid,1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private String getCityId(List<CityBo> cList, String cellValue) {
|
|
|
+ for (CityBo cityBo : cList) {
|
|
|
+ if (cityBo.getName().contains(cellValue)) {
|
|
|
+ return cityBo.getId().toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getProvinceId(List<ProvinceBo> pList, String cellValue) {
|
|
|
+ for (ProvinceBo provinceBo : pList) {
|
|
|
+ if (provinceBo.getName().contains(cellValue)) {
|
|
|
+ return provinceBo.getId().toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OutUserChannel> getErorrList() {
|
|
|
+ return userChannelMapper.selectByAidAndstatus(TokenManager.getAdminId(),1);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|