qa-prevention-gwj/src/main/java/com/zcloud/service/xgf/impl/XgfUserServiceImpl.java

190 lines
7.6 KiB
Java

package com.zcloud.service.xgf.impl;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.datasource.xgf.XgfUserDetailsMapper;
import com.zcloud.mapper.datasource.xgf.XgfUserMapper;
import com.zcloud.service.bus.CorpInfoService;
import com.zcloud.service.system.DepartmentService;
import com.zcloud.service.xgf.XgfUserService;
import com.zcloud.util.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class XgfUserServiceImpl implements XgfUserService {
@Resource
private XgfUserMapper xgfUserMapper;
@Resource
private XgfUserDetailsMapper xgfUserDetailsMapper;
@Resource
private DepartmentService departmentService;
@Value("${preventionxgf.api.url}")
private String prevention_xgf_url;
@Override
public void save(PageData pd) throws Exception {
xgfUserMapper.save(pd);
}
@Override
public void saveDetail(PageData pd) throws Exception {
xgfUserDetailsMapper.save(pd);
}
@Override
public List<PageData> list(Page page) throws Exception {
return xgfUserDetailsMapper.listPage(page);
}
@Override
@Transactional
public void init(PageData request) throws Exception {
List<PageData> list = Warden.getList(request.getString("infoList"));
PageData condition = new PageData();
for (PageData x : list) {
if (StringUtils.isNotBlank(x.getString("USER_ID"))) {
condition.put("XGF_USER_ID", x.getString("USER_ID"));
PageData entity = xgfUserMapper.findById(condition);
if (entity == null || entity.size() <= 0) {
x.put("XGF_USER_ID", x.get("USER_ID"));
x.put("XGF_USER_DETAILS_ID", x.get("USER_ID"));
x.put("XGF_USER_NAME", x.get("NAME"));
x.put("VALID_FLAG", "1");
x.put("STATUS", "2");
x.put("CREATED_TIME", DateUtil.getTime());
x.put("OPERATOR_TIME", DateUtil.getTime());
x.put("IS_DELETE", "0");
x.put("CREATE_TIME", DateUtil.getTime());
/* 监管部门 */
condition.clear();
condition.put("DEPARTMENT_ID", x.get("MANAGER_DEPARTMENT_ID"));
PageData regDepartmentEntity = departmentService.getCorpDepartment(condition);
if (regDepartmentEntity != null && regDepartmentEntity.size() > 0) {
x.put("MANAGER_DEPARTMENT_NAME", regDepartmentEntity.get("NAME"));
}
/* 主管部门 */
condition.clear();
condition.put("DEPARTMENT_ID", x.get("MAIN_DEPARTMENT_ID"));
regDepartmentEntity = departmentService.getCorpDepartment(condition);
x.put("MAIN_DEPARTMENT_NAME", regDepartmentEntity.get("NAME"));
if (regDepartmentEntity.size() > 0) {
x.put("MAIN_DEPARTMENT_NAME", regDepartmentEntity.get("NAME"));
}
xgfUserMapper.save(x);
xgfUserDetailsMapper.save(x);
} else {
x.put("XGF_USER_ID", x.get("USER_ID"));
x.put("XGF_USER_DETAILS_ID", x.get("USER_ID"));
x.put("IS_DELETE", "0");
x.put("CREATE_TIME", DateUtil.getTime());
x.put("OPERATOR_TIME", DateUtil.getTime());
/* 监管部门 */
condition.clear();
condition.put("DEPARTMENT_ID", x.get("MANAGER_DEPARTMENT_ID"));
PageData regDepartmentEntity = departmentService.getCorpDepartment(condition);
if (regDepartmentEntity != null && regDepartmentEntity.size() > 0) {
x.put("MANAGER_DEPARTMENT_NAME", regDepartmentEntity.get("NAME"));
}
/* 主管部门 */
condition.clear();
condition.put("DEPARTMENT_ID", x.get("MAIN_DEPARTMENT_ID"));
regDepartmentEntity = departmentService.getCorpDepartment(condition);
x.put("MAIN_DEPARTMENT_NAME", regDepartmentEntity.get("NAME"));
if (regDepartmentEntity.size() > 0) {
x.put("MAIN_DEPARTMENT_NAME", regDepartmentEntity.get("NAME"));
}
x.put("IS_DELETE", "0");
x.put("VALID_FLAG", "1");
x.put("STATUS", "2");
xgfUserMapper.edit(x);
xgfUserDetailsMapper.edit(x);
}
}
}
}
@Override
public void approvalApplication(PageData request) throws Exception {
List<String> list = Arrays.asList(request.getString("xgf_user_ids").split(","));
PageData condition = new PageData();
condition.put("XGF_USER_IDS", list);
List<PageData> entities = xgfUserMapper.listByIds(condition);
/* 校验所有数据是否都是正常状态 */
if (entities.stream().anyMatch(n -> !"2".equals(n.getString("STATUS")))) {
String name = entities.stream().filter(n -> !"2".equals(n.getString("STATUS"))).map( n -> n.getString("NAME")).collect(Collectors.joining(","));
throw new RuntimeException("用户[" + name + "]在系统流程中无法被打回");
}
for (PageData x : entities) {
x.put("VALID_FLAG", "0");
x.put("STATUS", "1");
xgfUserMapper.edit(x);
}
}
@Override
public List<PageData> flowlistPage(Page page) throws Exception {
return xgfUserMapper.flowlistPage(page);
}
@Override
@Transactional
public void approve(PageData request) throws Exception {
List<PageData> _list = Warden.getList(request.getString("list"));
if (_list == null || _list.size() == 0) {
throw new RuntimeException("请求数据异常");
}
List<String> list = _list.stream().map(x -> x.getString("XGF_USER_ID")).collect(Collectors.toList());
PageData condition = new PageData();
for (String x : list) {
condition.put("XGF_USER_ID", x);
PageData entity = xgfUserMapper.findById(condition);
if (entity == null || entity.size() == 0) {
throw new RuntimeException("未找到该用户");
}
if ("1".equals(request.getString("STATUS"))) {
entity.put("STATUS", "0");
} else {
entity.put("STATUS", "2");
entity.put("VALID_FLAG", "1");
}
xgfUserMapper.edit(entity);
entity.put("USER_ID", condition.get("XGF_USER_ID"));
entity.put("STATUS", request.getString("STATUS"));
Map result = HttpClientService.doPost(prevention_xgf_url + "openApi/user/approve", entity);
if (result == null || !"succeed".equals(result.get("result"))) {
throw new RuntimeException("请求失败");
}
}
}
@Override
public PageData findInfo(PageData condition) {
return xgfUserMapper.getInfoById(condition);
}
@Override
public List<PageData> findRecordList(PageData condition) throws Exception {
return xgfUserMapper.findRecordList(condition);
}
}