|  |  |  | 
|---|
|  |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
|---|
|  |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.LinkedHashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(units)){ | 
|---|
|  |  |  | responsibilityUnit.setIsDel(Constants.NOT_DELETE); | 
|---|
|  |  |  | responsibilityUnit.setCreateTime(new Date()); | 
|---|
|  |  |  | responsibilityUnit.setState(0); | 
|---|
|  |  |  | responsibilityUnit.setIsInvalid(0); | 
|---|
|  |  |  | responsibilityUnit.setCreateId(accountInfoDTO.getAccount().getId()); | 
|---|
|  |  |  | responsibilityUnit.setCreateName(accountInfoDTO.getAccount().getUserName()); | 
|---|
|  |  |  | 
|---|
|  |  |  | responsibilityUnit.setUpdateId(accountInfoDTO.getAccount().getId()); | 
|---|
|  |  |  | responsibilityUnit.setUpdateName(accountInfoDTO.getAccount().getUserName()); | 
|---|
|  |  |  | responsibilityUnit.setUpdateTime(new Date()); | 
|---|
|  |  |  | responsibilityUnit.setValue(JSONArray.toJSONString(responsibilityUnit.getParentCodeList())); | 
|---|
|  |  |  | responsibilityUnitMapper.insert(responsibilityUnit); | 
|---|
|  |  |  | return 200; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | Page<ResponsibilityUnit> responsibilityUnitPage = responsibilityUnitMapper.selectPage(pageList, wrapper); | 
|---|
|  |  |  | for (ResponsibilityUnit record : responsibilityUnitPage.getRecords()) { | 
|---|
|  |  |  | Integer areaCode = record.getAreaCode(); | 
|---|
|  |  |  | SysArea areaName = sysAreaService.select(areaCode); | 
|---|
|  |  |  | SysArea sysArea= sysAreaService.select(areaCode); | 
|---|
|  |  |  | Integer parentCode = record.getParentCode(); | 
|---|
|  |  |  | SysArea parentName = sysAreaService.select(parentCode); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(areaName) || ObjectUtils.isEmpty(parentName)){ | 
|---|
|  |  |  | SysArea parentArea = sysAreaService.select(parentCode); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(sysArea) || ObjectUtils.isEmpty(parentArea)){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | record.setAreaName(areaName.getAreaName()); | 
|---|
|  |  |  | record.setParentName(parentName.getAreaName()); | 
|---|
|  |  |  | record.setAreaName(sysArea.getAreaName()); | 
|---|
|  |  |  | record.setParentName(parentArea.getAreaName()); | 
|---|
|  |  |  | record.setParentCodeList(JSONObject.parseObject(record.getValue(),List.class)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map<String, Object> result = new LinkedHashMap<>(); | 
|---|
|  |  |  | result.put("total", pageList.getTotal()); | 
|---|
|  |  |  | 
|---|
|  |  |  | public Integer updateUnit(ResponsibilityUnit responsibilityUnit) { | 
|---|
|  |  |  | QueryWrapper<ResponsibilityUnit> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("unit_name",responsibilityUnit.getUnitName()); | 
|---|
|  |  |  | List<ResponsibilityUnit> units = responsibilityUnitMapper.selectList(wrapper); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(units)){ | 
|---|
|  |  |  | wrapper.eq("area_code",responsibilityUnit.getAreaCode()); | 
|---|
|  |  |  | ResponsibilityUnit responsibilityUnit2 = responsibilityUnitMapper.selectOne(wrapper); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(responsibilityUnit2)){ | 
|---|
|  |  |  | AccountInfoDTO account = getAccount(); | 
|---|
|  |  |  | responsibilityUnit.setUpdateId(account.getAccount().getId()); | 
|---|
|  |  |  | responsibilityUnit.setUpdateName(account.getAccount().getUserName()); | 
|---|
|  |  |  | responsibilityUnit.setUpdateTime(new Date()); | 
|---|
|  |  |  | responsibilityUnit.setValue(JSONArray.toJSONString(responsibilityUnit.getParentCodeList())); | 
|---|
|  |  |  | //                responsibilityUnit.setParentCodeList(JSONObject.parseObject(responsibilityUnit.getValue(),List.class)); | 
|---|
|  |  |  | responsibilityUnitMapper.updateById(responsibilityUnit); | 
|---|
|  |  |  | return 200; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | * | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateState(Integer id) { | 
|---|
|  |  |  | ResponsibilityUnit responsibilityUnit = responsibilityUnitMapper.selectById(id); | 
|---|
|  |  |  | responsibilityUnit.setState(1); | 
|---|
|  |  |  | public void updateState(Integer unitId) { | 
|---|
|  |  |  | ResponsibilityUnit responsibilityUnit = responsibilityUnitMapper.selectById(unitId); | 
|---|
|  |  |  | responsibilityUnit.setState(Constants.NOT_DELETE); | 
|---|
|  |  |  | AccountInfoDTO account = getAccount(); | 
|---|
|  |  |  | responsibilityUnit.setUpdateId(account.getAccount().getId()); | 
|---|
|  |  |  | responsibilityUnit.setUpdateName(account.getAccount().getUserName()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 是否作废 | 
|---|
|  |  |  | * @param id | 
|---|
|  |  |  | * @param unitId | 
|---|
|  |  |  | * @param code | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateInvalid(Integer id, String code) { | 
|---|
|  |  |  | ResponsibilityUnit responsibilityUnit = responsibilityUnitMapper.selectById(id); | 
|---|
|  |  |  | public void updateInvalid(Integer unitId, String code) { | 
|---|
|  |  |  | ResponsibilityUnit responsibilityUnit = responsibilityUnitMapper.selectById(unitId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | responsibilityUnit.setIsInvalid(1); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(code)){ | 
|---|
|  |  |  | responsibilityUnit.setInvalidReason(code); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取用户信息 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private AccountInfoDTO getAccount(){ | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|