| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- package platform.modules.government.service;
- import com.alibaba.fastjson.JSONObject;
- import com.aliyuncs.exceptions.ClientException;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import org.apache.poi.ss.formula.functions.T;
- import org.apache.tomcat.util.bcel.Const;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.ui.ModelMap;
- import org.springframework.util.ObjectUtils;
- import org.springframework.util.StringUtils;
- import platform.common.Constant;
- import platform.common.base.model.DictionaryItem;
- import platform.common.base.model.Template;
- import platform.common.base.service.BaseService;
- import platform.common.base.service.DictionaryItemService;
- import platform.common.base.service.TemplateService;
- import platform.common.exception.BaseException;
- import platform.common.util.AlibabaSMSUtil;
- import platform.common.util.DateUtil;
- import platform.common.util.GenerateNoUtil;
- import platform.common.util.ShiroUtils;
- import platform.modules.company.entity.ProjectMaterial;
- import platform.modules.company.entity.ProjectMatters;
- import platform.modules.company.entity.ProjectProvinces;
- import platform.modules.company.service.ProjectMaterialService;
- import platform.modules.company.service.ProjectProvincesService;
- import platform.modules.government.dao.RetreatOptimizationDao;
- import platform.modules.government.dto.SearchCondition;
- import platform.modules.government.entity.*;
- import platform.modules.sys.entity.*;
- import platform.modules.sys.service.*;
- import tk.mybatis.mapper.entity.Example;
- import tk.mybatis.mapper.util.StringUtil;
- import java.util.*;
- /**
- * @author kevin
- * @since 2019/3/14 10:55 AM
- */
- @Service
- @Transactional
- public class RetreatOptimizationService extends BaseService<RetreatOptimization> {
- @Autowired
- private RetreatOptimizationDao retreatOptimizationDao;
- @Autowired
- private ProjectMaterialService projectMaterialService;
- @Autowired
- private AttachmentService attachmentService;
- @Autowired
- private ApprovalService approvalService;
- @Autowired
- private TemplateService templateService;
- @Autowired
- private UserService userService;
- @Autowired
- private DepartmentService departmentService;
- @Autowired
- private DictionaryItemService dictionaryItemService;
- @Autowired
- private StreetService streetService;
- @Autowired
- private MessageService messageService;
- @Autowired
- private GroupService groupService;
- @Autowired
- private UserGroupService userGroupService;
- @Autowired
- private WaitToDoService waitToDoService;
- /**
- * 退二优二列表
- *
- * @param condition
- * @return
- */
- public PageInfo<RetreatOptimization> findByCondition(SearchCondition condition) {
- PageHelper.startPage(condition.getPageNum(), condition.getPageSize());
- if (condition.getStreet_id() != null){
- condition.setStreet_id(condition.getStreet_id());
- }
- else {
- condition.setStreet_id(ShiroUtils.getStreetId());
- }
- condition.setUser_type(ShiroUtils.getUserType());
- List<RetreatOptimization> list = retreatOptimizationDao.findByCondition(condition);
- if (!ObjectUtils.isEmpty(list)){
- for (RetreatOptimization retreatOptimization : list) {
- Street street = streetService.findById(retreatOptimization.getPlate());
- retreatOptimization.setPlateName(street.getName());
- //是否可审核
- if(null != ShiroUtils.getStreetId()){
- //街道用户
- if(retreatOptimization.getStatus().equals(Constant.RetreatOptimizationStatus.SUBMIT)){
- Group group = groupService.findByNameAndUserType(Constant.RETREAT,null,Constant.UserType.STREET,retreatOptimization.getPlate());
- if (null != group) {
- List<UserGroup> userGroups = userGroupService.findByGroupId(group.getId());
- for (UserGroup userGroup : userGroups) {
- if (ShiroUtils.getUserId().equals(userGroup.getUser_id())) {
- retreatOptimization.setCanAudit(true);
- }
- }
- }
- }
- }else{
- //政府用户
- if(retreatOptimization.getStatus().equals(Constant.RetreatOptimizationStatus.PENDINGRECEIVED)){
- Group group = groupService.findByNameAndUserType(Constant.RETREAT,null,Constant.UserType.GOVERNMENT, null);
- if (null != group) {
- List<UserGroup> userGroups = userGroupService.findByGroupId(group.getId());
- for (UserGroup userGroup : userGroups) {
- if (userGroup.getUser_id().equals(ShiroUtils.getUserId())){
- retreatOptimization.setCanAudit(true);
- break;
- }
- }
- }
- }
- }
- if (retreatOptimization.getStatus().equals(Constant.RetreatOptimizationStatus.REJECT)){
- if (retreatOptimization.getCreate_by().equals(ShiroUtils.getUserId())){
- retreatOptimization.setCanEdit(true);
- }
- }
- }
- }
- return new PageInfo<>(list);
- }
- /**
- * 新建退二优二
- *
- * @param retreatOptimization
- */
- public void saveRetreatOptimization(RetreatOptimization retreatOptimization) {
- String no = GenerateNoUtil.generateProjectApplyNo(Constant.ProjectNoHeader.RETREAT_OPTIMIZATION);
- retreatOptimization.setCommit_time(DateUtil.getTimeString(new Date()));
- retreatOptimization.setStatus(1);
- retreatOptimization.setNo(no);
- retreatOptimization.setPlate(ShiroUtils.getStreetId());
- retreatOptimization.setIs_read(false);
- this.insertAndGetId(retreatOptimization);
- //保存材料
- if (retreatOptimization.getMaterials() != null && retreatOptimization.getMaterials().size() > 0){
- List<Template> templateList = retreatOptimization.getMaterials();
- for (Template template : templateList) {
- ProjectMaterial material = new ProjectMaterial();
- material.setApply_id(retreatOptimization.getId());
- material.setMaterial_type(5);
- material.setTemplate_id(template.getId());
- projectMaterialService.insertAndGetId(material);
- //更新文件
- int fileId = template.getFileDown().getFile_id();
- Attachment attachment = attachmentService.findById(fileId);
- attachment.setBusiness_id(material.getId());
- attachment.setBusiness_type(Constant.Attachment.RETREAT_OPTIMIZATION);
- attachmentService.updateSelective(attachment);
- }
- }
- //新增流程
- Approval approval = new Approval();
- approval.setApply_id(retreatOptimization.getId());
- approval.setType(Constant.DictionaryType.RETREAT_OPTIMIZATION);
- approval.setOper_type("提交");
- Integer departmentId = userService.findById(ShiroUtils.getUserId()).getDepartment_id();
- if (departmentId != null){
- Department department = departmentService.findById(departmentId);
- approval.setDepartment(department.getName());
- }
- approvalService.insertAndGetId(approval);
- //发送通知
- saveMessage(retreatOptimization);
- }
- /**
- * 发送信息
- *
- * @param retreatOptimization
- */
- private void saveMessage(RetreatOptimization retreatOptimization) {
- Message message = new Message();
- message.setApply_id(retreatOptimization.getId());
- message.setTitle(" 退二优二");
- String content = "您好,"+ShiroUtils.getUserName() + ",提交的编号为"+retreatOptimization.getNo()+"的退二优二需要你查看。";
- message.setContent(content);
- message.setBusiness_type(Constant.Message_Business_type.RETREAT_OPTIMIZATION);
- //获取组
- if(retreatOptimization.getStatus().equals(Constant.RetreatOptimizationStatus.SUBMIT)){
- //街道审核
- Group group = groupService.findByNameAndUserType(Constant.RETREAT,null,Constant.UserType.STREET,retreatOptimization.getPlate());
- if (null == group) {
- throw new BaseException("操作失败,退二优二组没有审核人员,请联系管理员配置");
- }
- List<UserGroup> userGroups = userGroupService.findByGroupId(group.getId());
- int[] streetArrInt = new int[userGroups.size()];
- StringBuilder sb = new StringBuilder("");
- for (int i = 0 ;i<userGroups.size();i++) {
- streetArrInt[i] = userGroups.get(i).getUser_id();
- sb.append(userGroups.get(i).getUser_id()).append(",");
- }
- messageService.saveMessageAndPush(message, streetArrInt, Constant.UserType.STREET);
- //发送代办
- waitToDoService.newTODO("退二优二审核", "/retreatOpt/audit/" + retreatOptimization.getId(), Constant.WaitToDo_OperType.AUDIT, retreatOptimization.getId(),
- Constant.DictionaryType.RETREAT_OPTIMIZATION, retreatOptimization.getNo(), sb.toString(), Constant.WaitToDo_IsSerial.IS_SERIAL, false);
- }else if(retreatOptimization.getStatus().equals(Constant.RetreatOptimizationStatus.PENDINGRECEIVED)){
- //政府审核
- Group group = groupService.findByNameAndUserType(Constant.RETREAT,null,Constant.UserType.GOVERNMENT, null);
- if (null == group) {
- throw new BaseException("操作失败,退二优二组没有审核人员,请联系管理员配置");
- }
- List<UserGroup> userGroups = userGroupService.findByGroupId(group.getId());
- StringBuilder sb = new StringBuilder("");
- for (UserGroup userGroup : userGroups) {
- // User user = userService.findById(userGroup.getUser_id());
- int[] streetArrInt = new int[1];
- streetArrInt[0] = userGroup.getUser_id();
- sb.append(userGroup.getUser_id()).append(",");
- messageService.saveMessageAndPush(message, streetArrInt, Constant.UserType.GOVERNMENT);
- }
- //发送代办
- waitToDoService.newTODO("退二优二审核", "/retreatOpt/audit/" + retreatOptimization.getId(), Constant.WaitToDo_OperType.AUDIT, retreatOptimization.getId(),
- Constant.DictionaryType.RETREAT_OPTIMIZATION, retreatOptimization.getNo(), sb.toString(), Constant.WaitToDo_IsSerial.IS_SERIAL, false);
- }
- }
- /**
- * 获取详情
- *
- * @param id
- * @return
- */
- @Transactional(readOnly = true)
- public RetreatOptimization findDetail(Integer id, ModelMap modelMap) {
- RetreatOptimization retreatOptimization = this.findById(id);
- //获取基本信息
- getFullBaseInfo(retreatOptimization);
- List<Template> materials = new ArrayList<>();
- //获取材料
- ProjectMaterial material = new ProjectMaterial();
- material.setApply_id(retreatOptimization.getId());
- material.setMaterial_type(5);
- material.setDel_flag(false);
- List<ProjectMaterial> materialList = projectMaterialService.findListByWhere(material);
- for (ProjectMaterial projectMaterial : materialList) {
- //上传文件
- Attachment attachment = attachmentService.
- findByBizIdAndBizType(projectMaterial.getId(), Constant.Attachment.RETREAT_OPTIMIZATION);
- //获取模版文件
- Attachment templateFile = attachmentService.
- findByBizIdAndBizType(projectMaterial.getTemplate_id(), Constant.Attachment.TEMPLATE);
- Template template = templateService.findById(projectMaterial.getTemplate_id());
- if (templateFile != null) {
- template.setUrl(templateFile.getFile_url());
- template.setItem_name(templateFile.getFile_name());
- }
- templateService.getFullTemplateInfo(template);
- if (attachment != null){
- FileDown fileDown = new FileDown();
- fileDown.setFile_id(attachment.getId());
- fileDown.setFile_name(attachment.getFile_name());
- fileDown.setDownload_uri(attachment.getDownload_uri());
- fileDown.setFile_url(attachment.getFile_url());
- template.setFileDown(fileDown);
- }
- materials.add(template);
- }
- retreatOptimization.setMaterials(materials);
- modelMap.put("materials", materials);
- //获取流程
- List<Approval> approvalList = approvalService.
- getListByApplyIdAndType(retreatOptimization.getId(), Constant.DictionaryType.RETREAT_OPTIMIZATION);
- retreatOptimization.setApprovals(approvalList);
- modelMap.put("approvals", approvalList);
- if (ShiroUtils.getUserId() == retreatOptimization.getCreate_by()){
- //是否在街道审核组
- if (inGroup(Constant.RETREAT, ShiroUtils.getStreetId())) {
- modelMap.put("canView", true);
- }
- }
- else {
- modelMap.put("canView", true);
- }
- Approval lastApproval = approvalService.getLatestApproval(retreatOptimization.getId(), Constant.DictionaryType.RETREAT_OPTIMIZATION);
- modelMap.put("lastApproval", lastApproval);
- return retreatOptimization;
- }
- private boolean inGroup(String groupName, Integer streetId) {
- Boolean flag = false;
- Group group = groupService.findByNameAndUserType(groupName, null, Constant.UserType.STREET, streetId);
- if (group != null) {
- List<UserGroup> userGroups = userGroupService.findByGroupId(group.getId());
- for (int i = 0; i < userGroups.size(); i++) {
- if (userGroups.get(i).getUser_id() == ShiroUtils.getUserId()) {
- flag = true;
- break;
- }
- }
- }
- return flag;
- }
- /**
- * 获取基本信息
- *
- * @param retreatOptimization
- */
- private void getFullBaseInfo(RetreatOptimization retreatOptimization) {
- Street street = streetService.findById(retreatOptimization.getPlate());
- retreatOptimization.setPlateName(street.getName());
- retreatOptimization.setUserName(ShiroUtils.getUserName());
- if (retreatOptimization.getStatus().equals(Constant.RetreatOptimizationStatus.SUBMIT)){
- retreatOptimization.setStatusStr("提交");
- }
- else if (retreatOptimization.getStatus().equals(Constant.RetreatOptimizationStatus.PENDINGRECEIVED)){
- retreatOptimization.setStatusStr("待确认接收");
- }
- else if (retreatOptimization.getStatus().equals(Constant.RetreatOptimizationStatus.RECEIVED)){
- retreatOptimization.setStatusStr("接收成功");
- }
- else {
- retreatOptimization.setStatusStr("退回");
- }
- //获取类型
- String typeStr = dictionaryItemService.findNameByTypeAndValue(
- Constant.DictionaryType.RETREAT_OPTIMIZATION, retreatOptimization.getType().toString());
- retreatOptimization.setTypeStr(typeStr);
- }
- /**
- * 更新退二优二
- *
- * @param retreatOptimization
- */
- public void updateRetreatOptimization(RetreatOptimization retreatOptimization) {
- if (retreatOptimization.getId() == null){
- throw new NullPointerException("系统错误");
- }
- RetreatOptimization optimization = this.findById(retreatOptimization.getId());
- //更新附件
- ProjectMaterial material = new ProjectMaterial();
- material.setApply_id(retreatOptimization.getId());
- material.setMaterial_type(5);
- // 判断类型是否相同
- if (!optimization.getType().equals(retreatOptimization.getType())){
- //不同类型的材料,先删除原有的材料
- List<ProjectMaterial> listByWhere = projectMaterialService.findListByWhere(material);
- if (!ObjectUtils.isEmpty(listByWhere)){
- for (ProjectMaterial projectMaterial : listByWhere) {
- projectMaterial.setDel_flag(true);
- projectMaterialService.updateSelective(projectMaterial);
- //删除材料文件
- Attachment old = new Attachment();
- old.setBusiness_type(Constant.Attachment.RETREAT_OPTIMIZATION);
- old.setBusiness_id(projectMaterial.getId());
- Attachment attachmentOne = attachmentService.findOne(old);
- if (attachmentOne != null){
- attachmentOne.setDel_flag(true);
- attachmentService.updateSelective(attachmentOne);
- }
- }
- }
- if (retreatOptimization.getMaterials() != null && retreatOptimization.getMaterials().size() > 0){
- List<Template> templateList = retreatOptimization.getMaterials();
- for (Template template : templateList) {
- //查询已有的materials
- material.setTemplate_id(template.getId());
- projectMaterialService.insertAndGetId(material);
- //更新文件
- int fileId = template.getFileDown().getFile_id();
- Attachment attachment = attachmentService.findById(fileId);
- if (attachment.getBusiness_type() == null){
- attachment.setBusiness_id(material.getId());
- attachment.setBusiness_type(Constant.Attachment.RETREAT_OPTIMIZATION);
- attachmentService.updateSelective(attachment);
- }
- }
- }
- }
- else {
- if (retreatOptimization.getMaterials() != null && retreatOptimization.getMaterials().size() > 0){
- List<Template> templateList = retreatOptimization.getMaterials();
- for (Template template : templateList) {
- //查询已有的materials
- material.setTemplate_id(template.getId());
- ProjectMaterial one = projectMaterialService.findOne(material);
- if (one != null){
- //删除已有的文件
- Attachment old = new Attachment();
- old.setBusiness_type(Constant.Attachment.RETREAT_OPTIMIZATION);
- old.setBusiness_id(one.getId());
- Attachment attachmentOne = attachmentService.findOne(old);
- if (attachmentOne != null){
- attachmentOne.setDel_flag(true);
- attachmentService.updateSelective(attachmentOne);
- }
- }
- else {
- projectMaterialService.insertAndGetId(material);
- //更新文件
- int fileId = template.getFileDown().getFile_id();
- Attachment attachment = attachmentService.findById(fileId);
- if (attachment.getBusiness_type() == null){
- attachment.setBusiness_id(material.getId());
- attachment.setBusiness_type(Constant.Attachment.RETREAT_OPTIMIZATION);
- attachmentService.updateSelective(attachment);
- }
- }
- }
- }
- }
- //处于退回状态
- if (optimization.getStatus() ==2){
- //新增流程
- Approval approval = new Approval();
- approval.setApply_id(retreatOptimization.getId());
- approval.setType(Constant.DictionaryType.RETREAT_OPTIMIZATION);
- approval.setOper_type("提交");
- approval.setBefore_approvalstatus("2");
- approval.setAfter_approvalstatus("1");
- Integer departmentId = userService.findById(ShiroUtils.getUserId()).getDepartment_id();
- if (departmentId != null){
- Department department = departmentService.findById(departmentId);
- approval.setDepartment(department.getName());
- }
- approvalService.insertAndGetId(approval);
- }
- optimization.setStatus(1);
- updateSelective(optimization);
- saveMessage(optimization);
- }
- /**
- * 退回
- *
- * @param id
- * @param approvalComment
- */
- public void retreat(Integer id, String approvalComment) {
- //删除代办
- waitToDoService.completeAllTODO(id, Constant.DictionaryType.RETREAT_OPTIMIZATION);
- RetreatOptimization retreatOptimization = findById(id);
- retreatOptimization.setStatus(2);
- updateSelective(retreatOptimization);
- //更新流程
- Approval approval = new Approval();
- approval.setApply_id(retreatOptimization.getId());
- approval.setType(Constant.DictionaryType.RETREAT_OPTIMIZATION);
- approval.setOper_type("退回");
- approval.setBefore_approvalstatus("1");
- approval.setAfter_approvalstatus("2");
- approval.setApproval_comment(approvalComment);
- Integer departmentId = userService.findById(ShiroUtils.getUserId()).getDepartment_id();
- if (departmentId != null){
- Department department = departmentService.findById(departmentId);
- approval.setDepartment(department.getName());
- }
- approvalService.insertAndGetId(approval);
- //发送短信
- sendPhoneMess(retreatOptimization, "退回");
- }
- private void sendPhoneMess(RetreatOptimization retreatOptimization, String result) {
- //发送短信
- try {
- String phone = userService.findById(retreatOptimization.getCreate_by()).getPhone();
- String templateCode = Constant.SMS_TemplateCode.RETREAT_OPTIMIZATION;
- Map<String, String> paramMap = new HashMap<>();
- paramMap.put("apply_no", retreatOptimization.getNo());
- paramMap.put("result", result);
- // paramMap.put("reason", approvalComment);
- AlibabaSMSUtil.sendSMSMessage(phone, templateCode, Constant.SINGNAMW, JSONObject.toJSONString(paramMap));
- } catch (ClientException e) {
- e.printStackTrace();
- }
- }
- /**
- * 通过
- *
- * @param id
- * @param approvalComment
- */
- public void approve(Integer id, String approvalComment) {
- //删除代办
- waitToDoService.completeTODO(id, Constant.DictionaryType.RETREAT_OPTIMIZATION);
- RetreatOptimization retreatOptimization = findById(id);
- Integer nextStatus = getNextStatus(retreatOptimization.getStatus(),true);
- retreatOptimization.setStatus(nextStatus);
- updateSelective(retreatOptimization);
- //更新流程
- Approval approval = new Approval();
- approval.setApply_id(retreatOptimization.getId());
- approval.setType(Constant.DictionaryType.RETREAT_OPTIMIZATION);
- approval.setOper_type("通过");
- approval.setBefore_approvalstatus(retreatOptimization.getStatus().toString());
- approval.setAfter_approvalstatus(nextStatus.toString());
- approval.setApproval_comment(approvalComment);
- Integer departmentId = userService.findById(ShiroUtils.getUserId()).getDepartment_id();
- if (departmentId != null){
- Department department = departmentService.findById(departmentId);
- approval.setDepartment(department.getName());
- }
- approvalService.insertAndGetId(approval);
- //确认接收
- if (nextStatus.equals(Constant.RetreatOptimizationStatus.RECEIVED)){
- sendPhoneMess(retreatOptimization, "通过");
- }
- if (nextStatus.equals(Constant.RetreatOptimizationStatus.PENDINGRECEIVED)){
- saveMessage(retreatOptimization);
- }
- }
- //获取下一状态
- public Integer getNextStatus(Integer currStatus,Boolean isApprove){
- if(!isApprove){
- //退回
- return Constant.RetreatOptimizationStatus.REJECT;
- }else{
- //通过
- if(null !=currStatus){
- if(currStatus.equals(Constant.RetreatOptimizationStatus.PENDINGRECEIVED)){
- return Constant.RetreatOptimizationStatus.RECEIVED;
- }else if(currStatus.equals(Constant.RetreatOptimizationStatus.SUBMIT)){
- return Constant.RetreatOptimizationStatus.PENDINGRECEIVED;
- }
- }
- }
- return null;
- }
- }
|