Commit 7a90bc7cf3af2a573ea12cb7420e846a4b94b886
1 parent
cc04b0e8
楚江ERP:1:判断当前人员是哪个办事处下的;2:客户资信编码生成修改
Showing
4 changed files
with
151 additions
and
15 deletions
xingyun-sc/src/main/java/com/lframework/xingyun/sc/controller/order/PurchaseOrderInfoController.java
| @@ -41,7 +41,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; | @@ -41,7 +41,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||
| 41 | import org.springframework.beans.factory.annotation.Autowired; | 41 | import org.springframework.beans.factory.annotation.Autowired; |
| 42 | import org.springframework.validation.annotation.Validated; | 42 | import org.springframework.validation.annotation.Validated; |
| 43 | import org.springframework.web.bind.annotation.*; | 43 | import org.springframework.web.bind.annotation.*; |
| 44 | - | ||
| 45 | import javax.annotation.Resource; | 44 | import javax.annotation.Resource; |
| 46 | import javax.servlet.http.HttpServletResponse; | 45 | import javax.servlet.http.HttpServletResponse; |
| 47 | import javax.validation.Valid; | 46 | import javax.validation.Valid; |
| @@ -360,6 +360,12 @@ public class CustomerCredit extends BaseEntity implements BaseDto { | @@ -360,6 +360,12 @@ public class CustomerCredit extends BaseEntity implements BaseDto { | ||
| 360 | private String userId; | 360 | private String userId; |
| 361 | 361 | ||
| 362 | /** | 362 | /** |
| 363 | + * 办事处code(非持久化字段) | ||
| 364 | + */ | ||
| 365 | + @TableField(exist = false) | ||
| 366 | + private String deptCode; | ||
| 367 | + | ||
| 368 | + /** | ||
| 363 | * 创建人ID | 369 | * 创建人ID |
| 364 | */ | 370 | */ |
| 365 | @TableField(fill = FieldFill.INSERT) | 371 | @TableField(fill = FieldFill.INSERT) |
| 1 | package com.lframework.xingyun.sc.handlers; | 1 | package com.lframework.xingyun.sc.handlers; |
| 2 | 2 | ||
| 3 | import com.lframework.starter.web.core.utils.JsonUtil; | 3 | import com.lframework.starter.web.core.utils.JsonUtil; |
| 4 | -import com.lframework.starter.web.inner.mappers.system.SysUserRoleMapper; | 4 | +import com.lframework.starter.web.inner.entity.SysDept; |
| 5 | +import com.lframework.starter.web.inner.entity.SysUserDept; | ||
| 6 | +import com.lframework.starter.web.inner.service.system.SysDeptService; | ||
| 5 | import com.lframework.starter.web.inner.service.system.SysUserDeptService; | 7 | import com.lframework.starter.web.inner.service.system.SysUserDeptService; |
| 6 | import com.lframework.starter.web.inner.service.system.SysUserRoleService; | 8 | import com.lframework.starter.web.inner.service.system.SysUserRoleService; |
| 7 | import com.lframework.xingyun.basedata.entity.Workshop; | 9 | import com.lframework.xingyun.basedata.entity.Workshop; |
| @@ -9,12 +11,9 @@ import com.lframework.xingyun.basedata.service.workshop.WorkshopService; | @@ -9,12 +11,9 @@ import com.lframework.xingyun.basedata.service.workshop.WorkshopService; | ||
| 9 | import lombok.extern.slf4j.Slf4j; | 11 | import lombok.extern.slf4j.Slf4j; |
| 10 | import org.apache.commons.collections4.CollectionUtils; | 12 | import org.apache.commons.collections4.CollectionUtils; |
| 11 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
| 12 | - | ||
| 13 | import javax.annotation.Resource; | 14 | import javax.annotation.Resource; |
| 14 | -import java.util.ArrayList; | ||
| 15 | -import java.util.Collections; | ||
| 16 | -import java.util.List; | ||
| 17 | -import java.util.Map; | 15 | +import java.util.*; |
| 16 | +import java.util.stream.Collectors; | ||
| 18 | 17 | ||
| 19 | @Component | 18 | @Component |
| 20 | @Slf4j | 19 | @Slf4j |
| @@ -26,6 +25,8 @@ public class TransactorHandler { | @@ -26,6 +25,8 @@ public class TransactorHandler { | ||
| 26 | private SysUserRoleService sysUserRoleService; | 25 | private SysUserRoleService sysUserRoleService; |
| 27 | @Resource | 26 | @Resource |
| 28 | private WorkshopService workshopService; | 27 | private WorkshopService workshopService; |
| 28 | + @Resource | ||
| 29 | + private SysDeptService sysDeptService; | ||
| 29 | 30 | ||
| 30 | 31 | ||
| 31 | /** | 32 | /** |
| @@ -94,4 +95,115 @@ public class TransactorHandler { | @@ -94,4 +95,115 @@ public class TransactorHandler { | ||
| 94 | log.info("================== listByRoleAndWorkshop invoke end, result:{}", JsonUtil.toJsonString(result)); | 95 | log.info("================== listByRoleAndWorkshop invoke end, result:{}", JsonUtil.toJsonString(result)); |
| 95 | return result; | 96 | return result; |
| 96 | } | 97 | } |
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * 判断当前人员是哪个办事处下的 | ||
| 101 | + * | ||
| 102 | + * @param userId 业务数据创建人/更新人ID | ||
| 103 | + * @return List<String> | ||
| 104 | + */ | ||
| 105 | + public String returnDeptCode(String userId) { | ||
| 106 | + log.info("================== returnDeptCode invoke start, userId:{}", userId); | ||
| 107 | + List<String> codeList = new ArrayList<>(); | ||
| 108 | + codeList.add("BF"); | ||
| 109 | + codeList.add("CZ"); | ||
| 110 | + codeList.add("DG"); | ||
| 111 | + codeList.add("FS"); | ||
| 112 | + codeList.add("NB"); | ||
| 113 | + codeList.add("SZ"); | ||
| 114 | + codeList.add("WZ"); | ||
| 115 | + codeList.add("ZT"); | ||
| 116 | + List<SysDept> byCodeList = sysDeptService.findByCodeList(codeList); | ||
| 117 | + List<String> deptIds = byCodeList.stream() | ||
| 118 | + .map(SysDept::getId) | ||
| 119 | + .collect(Collectors.toList()); | ||
| 120 | + Map<String, String> codeToIdMap = byCodeList.stream() | ||
| 121 | + .collect(Collectors.toMap( | ||
| 122 | + SysDept::getCode, | ||
| 123 | + SysDept::getId | ||
| 124 | + )); | ||
| 125 | + | ||
| 126 | + Map<String, List<String>> deptChildIdMap = sysDeptService.getDeptChildIdMap(deptIds); | ||
| 127 | + List<SysUserDept> userDepts = userDeptService.getByUserId(userId); | ||
| 128 | + //当前人部门 | ||
| 129 | + List<String> userDeptIds = new ArrayList<>(); | ||
| 130 | + if (CollectionUtils.isNotEmpty(userDepts)) { | ||
| 131 | + userDeptIds = userDepts.stream() | ||
| 132 | + .map(SysUserDept::getDeptId) | ||
| 133 | + .collect(Collectors.toList()); | ||
| 134 | + } | ||
| 135 | + String result = null; | ||
| 136 | + //北方 | ||
| 137 | + String bf = codeToIdMap.get("BF"); | ||
| 138 | + List<String> bfList = deptChildIdMap.get(bf); | ||
| 139 | + boolean bfBoolean = hasIntersection(bfList, userDeptIds); | ||
| 140 | + if (bfBoolean) { | ||
| 141 | + result = "BF"; | ||
| 142 | + } | ||
| 143 | + //常州 | ||
| 144 | + String cz = codeToIdMap.get("CZ"); | ||
| 145 | + List<String> czList = deptChildIdMap.get(cz); | ||
| 146 | + boolean czBoolean = hasIntersection(czList, userDeptIds); | ||
| 147 | + if (czBoolean) { | ||
| 148 | + result = "CZ"; | ||
| 149 | + } | ||
| 150 | + //东莞 | ||
| 151 | + String dg = codeToIdMap.get("DG"); | ||
| 152 | + List<String> dgList = deptChildIdMap.get(dg); | ||
| 153 | + boolean dgBoolean = hasIntersection(dgList, userDeptIds); | ||
| 154 | + if (dgBoolean) { | ||
| 155 | + result = "DG"; | ||
| 156 | + } | ||
| 157 | + //佛山 | ||
| 158 | + String fs = codeToIdMap.get("FS"); | ||
| 159 | + List<String> fsList = deptChildIdMap.get(fs); | ||
| 160 | + boolean fsBoolean = hasIntersection(fsList, userDeptIds); | ||
| 161 | + if (fsBoolean) { | ||
| 162 | + result = "FS"; | ||
| 163 | + } | ||
| 164 | + //宁波 | ||
| 165 | + String nb = codeToIdMap.get("NB"); | ||
| 166 | + List<String> nbList = deptChildIdMap.get(nb); | ||
| 167 | + boolean nbBoolean = hasIntersection(nbList, userDeptIds); | ||
| 168 | + if (nbBoolean) { | ||
| 169 | + result = "NB"; | ||
| 170 | + } | ||
| 171 | + //苏州 | ||
| 172 | + String sz = codeToIdMap.get("SZ"); | ||
| 173 | + List<String> szList = deptChildIdMap.get(sz); | ||
| 174 | + boolean szBoolean = hasIntersection(szList, userDeptIds); | ||
| 175 | + if (szBoolean) { | ||
| 176 | + result = "SZ"; | ||
| 177 | + } | ||
| 178 | + //温州 | ||
| 179 | + String wz = codeToIdMap.get("WZ"); | ||
| 180 | + List<String> wzList = deptChildIdMap.get(wz); | ||
| 181 | + boolean wzBoolean = hasIntersection(wzList, userDeptIds); | ||
| 182 | + if (wzBoolean) { | ||
| 183 | + result = "WZ"; | ||
| 184 | + } | ||
| 185 | + //紫铜 | ||
| 186 | + String zt = codeToIdMap.get("ZT"); | ||
| 187 | + List<String> ztList = deptChildIdMap.get(zt); | ||
| 188 | + boolean ztBoolean = hasIntersection(ztList, userDeptIds); | ||
| 189 | + if (ztBoolean) { | ||
| 190 | + result = "ZT"; | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + | ||
| 194 | + log.info("================== returnDeptCode invoke end, result:{}", result); | ||
| 195 | + return result; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + //判断两个集合是否有交集 | ||
| 199 | + public static <T> boolean hasIntersection(Collection<T> a, Collection<T> b) { | ||
| 200 | + if (a.isEmpty() || b.isEmpty()) { | ||
| 201 | + return false; | ||
| 202 | + } | ||
| 203 | + // 将较小的集合作为 contains 的目标,提升性能 | ||
| 204 | + Collection<T> smaller = a.size() <= b.size() ? a : b; | ||
| 205 | + Collection<T> larger = a.size() > b.size() ? a : b; | ||
| 206 | + | ||
| 207 | + return larger.stream().anyMatch(smaller::contains); | ||
| 208 | + } | ||
| 97 | } | 209 | } |
| @@ -35,6 +35,7 @@ import com.lframework.starter.web.core.annotations.oplog.OpLog; | @@ -35,6 +35,7 @@ import com.lframework.starter.web.core.annotations.oplog.OpLog; | ||
| 35 | import com.lframework.starter.common.utils.Assert; | 35 | import com.lframework.starter.common.utils.Assert; |
| 36 | import com.lframework.starter.web.inner.components.oplog.OtherOpLogType; | 36 | import com.lframework.starter.web.inner.components.oplog.OtherOpLogType; |
| 37 | import com.lframework.xingyun.sc.entity.CustomerCreditHistory; | 37 | import com.lframework.xingyun.sc.entity.CustomerCreditHistory; |
| 38 | +import com.lframework.xingyun.sc.handlers.TransactorHandler; | ||
| 38 | import com.lframework.xingyun.sc.mappers.CustomerCreditMapper; | 39 | import com.lframework.xingyun.sc.mappers.CustomerCreditMapper; |
| 39 | import com.lframework.xingyun.sc.service.customer.CorePersonnelHistoryService; | 40 | import com.lframework.xingyun.sc.service.customer.CorePersonnelHistoryService; |
| 40 | import com.lframework.xingyun.sc.service.customer.CorePersonnelService; | 41 | import com.lframework.xingyun.sc.service.customer.CorePersonnelService; |
| @@ -94,6 +95,8 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM | @@ -94,6 +95,8 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM | ||
| 94 | private SysUserDeptService sysUserDeptService; | 95 | private SysUserDeptService sysUserDeptService; |
| 95 | @Value("${customer.credit.export:/web/service/erp/xingyun/export/templates/}") | 96 | @Value("${customer.credit.export:/web/service/erp/xingyun/export/templates/}") |
| 96 | private String exportTemplate; | 97 | private String exportTemplate; |
| 98 | + @Resource | ||
| 99 | + private TransactorHandler transactorHandler; | ||
| 97 | 100 | ||
| 98 | @Override | 101 | @Override |
| 99 | public PageResult<CustomerCredit> query(Integer pageIndex, Integer pageSize, QueryCustomerCreditVo vo) { | 102 | public PageResult<CustomerCredit> query(Integer pageIndex, Integer pageSize, QueryCustomerCreditVo vo) { |
| @@ -315,6 +318,8 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM | @@ -315,6 +318,8 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM | ||
| 315 | if (!"IMPORT".equals(vo.getImportType())) { | 318 | if (!"IMPORT".equals(vo.getImportType())) { |
| 316 | // 开启审核 | 319 | // 开启审核 |
| 317 | data.setUserId(SecurityUtil.getCurrentUser().getId()); | 320 | data.setUserId(SecurityUtil.getCurrentUser().getId()); |
| 321 | + String deptCode = transactorHandler.returnDeptCode(SecurityUtil.getCurrentUser().getId()); | ||
| 322 | + data.setDeptCode(deptCode); | ||
| 318 | flowInstanceWrapperService.startInstance(BPM_FLAG, data.getId(), BPM_FLAG, data); | 323 | flowInstanceWrapperService.startInstance(BPM_FLAG, data.getId(), BPM_FLAG, data); |
| 319 | } | 324 | } |
| 320 | 325 | ||
| @@ -906,6 +911,8 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM | @@ -906,6 +911,8 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM | ||
| 906 | 911 | ||
| 907 | //开启审核 | 912 | //开启审核 |
| 908 | vo.setUserId(SecurityUtil.getCurrentUser().getId()); | 913 | vo.setUserId(SecurityUtil.getCurrentUser().getId()); |
| 914 | + String deptCode = transactorHandler.returnDeptCode(SecurityUtil.getCurrentUser().getId()); | ||
| 915 | + data.setDeptCode(deptCode); | ||
| 909 | flowInstanceWrapperService.startInstance(BPM_FLAG, data.getId(), BPM_FLAG, vo); | 916 | flowInstanceWrapperService.startInstance(BPM_FLAG, data.getId(), BPM_FLAG, vo); |
| 910 | } | 917 | } |
| 911 | 918 | ||
| @@ -1270,14 +1277,26 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM | @@ -1270,14 +1277,26 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM | ||
| 1270 | if (sysUser != null) { | 1277 | if (sysUser != null) { |
| 1271 | GetSysUserBo getSysUserBo = new GetSysUserBo(sysUser); | 1278 | GetSysUserBo getSysUserBo = new GetSysUserBo(sysUser); |
| 1272 | //部门名称 | 1279 | //部门名称 |
| 1273 | - String deptName = getSysUserBo.getDeptName(); | ||
| 1274 | - if (StringUtil.isNotEmpty(deptName)) { | ||
| 1275 | - //获取办事处首字母 | ||
| 1276 | - String prefixPinyin = getPrefixPinyin(deptName); | ||
| 1277 | - //已使用编号 | ||
| 1278 | - Set<String> existingNumbers = customerCreditMapper.getGenerateCode(prefixPinyin); | ||
| 1279 | - | ||
| 1280 | - return generateNextAvailableNumber(prefixPinyin, existingNumbers); | 1280 | + List<String> depts = getSysUserBo.getDepts(); |
| 1281 | + if (CollectionUtils.isNotEmpty(depts)) { | ||
| 1282 | + SysDept sysDept = sysDeptService.findById(depts.get(0)); | ||
| 1283 | + String parentId = sysDept.getParentId(); | ||
| 1284 | + if (StringUtil.isNotEmpty(parentId)) { | ||
| 1285 | + SysDept sysDept1 = sysDeptService.findById(parentId); | ||
| 1286 | + //获取办事处首字母 | ||
| 1287 | + String prefixPinyin = getPrefixPinyin(sysDept1.getName()); | ||
| 1288 | + //已使用编号 | ||
| 1289 | + Set<String> existingNumbers = customerCreditMapper.getGenerateCode(prefixPinyin); | ||
| 1290 | + | ||
| 1291 | + return generateNextAvailableNumber(prefixPinyin, existingNumbers); | ||
| 1292 | + } else { | ||
| 1293 | + //获取办事处首字母 | ||
| 1294 | + String prefixPinyin = getPrefixPinyin(sysDept.getName()); | ||
| 1295 | + //已使用编号 | ||
| 1296 | + Set<String> existingNumbers = customerCreditMapper.getGenerateCode(prefixPinyin); | ||
| 1297 | + | ||
| 1298 | + return generateNextAvailableNumber(prefixPinyin, existingNumbers); | ||
| 1299 | + } | ||
| 1281 | } else { | 1300 | } else { |
| 1282 | throw new DefaultClientException("部门名称为空"); | 1301 | throw new DefaultClientException("部门名称为空"); |
| 1283 | } | 1302 | } |