package platform.modules.government.web; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.springframework.web.multipart.MultipartFile; import platform.common.Constant; import platform.common.annotation.OperationLog; import platform.common.base.controller.BaseController; import platform.common.base.model.DictionaryItem; import platform.common.base.model.DictionaryType; import platform.common.base.model.Template; import platform.common.base.service.DictionaryItemService; import platform.common.base.service.DictionaryTypeService; import platform.common.base.service.TemplateService; import platform.common.util.ReadExcelUtil; import platform.common.util.holiday.HolidayExcelParser; import platform.common.util.holiday.HolidayExcelTemplateUtil; import platform.modules.build.entity.BuildInfo; import platform.modules.build.service.BuildInfoService; import platform.modules.build.service.CompanyService; import platform.modules.government.dto.AttachmentDto; import platform.modules.government.entity.Attachment; import platform.modules.government.entity.BuildType; import platform.modules.government.entity.Street; import platform.modules.government.entity.User; import platform.modules.government.service.AttachmentService; import platform.modules.government.service.BuildTypeService; import platform.modules.government.service.StreetService; import platform.modules.government.service.UserService; import platform.modules.sys.entity.SysConfig; import platform.modules.sys.service.SysConfigService; import platform.modules.sys.web.ResponseMessage; import tk.mybatis.mapper.entity.Example; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @Controller @RequestMapping(value = "/super") public class SupermeController extends BaseController { @Autowired private StreetService streeService; @Autowired private BuildTypeService buildTypeService; @Autowired private BuildInfoService buildService; @Autowired private CompanyService companyService; @Autowired private DictionaryTypeService dictionaryTypeService; @Autowired private DictionaryItemService dictionaryItemService; @Autowired private TemplateService templateService; @Autowired private UserService userService; @Autowired private AttachmentService attachmentService; @Autowired private SysConfigService sysConfigService; @Resource private HolidayExcelTemplateUtil holidayExcelTemplateUtil; @GetMapping(value = "") public String list() { return BASE_SUPER_PATH + "/datadictionary"; } /** * 街道列表展示 * * @param pageNum * @param keyword * @param modelMap * @return * @throws Exception */ @OperationLog(value = "查询街道列表") @GetMapping(value = "/streeList") public String streeList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, String keyword, ModelMap modelMap) throws Exception { PageInfo pageInfo = streeService.findPage(pageNum, PAGESIZE, keyword); modelMap.put("pageInfo", pageInfo); modelMap.put("keyword", keyword); return BASE_SUPER_PATH + "/stree_list"; } @GetMapping(value = "/stree/add") public String addStreePage(ModelMap modelMap) { return BASE_SUPER_PATH + "/stree_add"; } @OperationLog(value = "街道信息保存") @ResponseBody @PostMapping(value = "/stree/save") public ModelMap saveStree(Street stree) throws Exception { ModelMap messagesMap = new ModelMap(); if(IsTooFrequently()) { messagesMap.put("status", FAILURE); messagesMap.put("message", "操作过于频繁,请稍后再试!"); return messagesMap; } Boolean flag = false; if (stree.getId() == null) { flag = streeService.saveStree(stree); } else { flag = streeService.updateStree(stree); } if (flag) { messagesMap.put("status", SUCCESS); messagesMap.put("message", "操作成功!"); return messagesMap; } messagesMap.put("status", FAILURE); messagesMap.put("message", "操作失败!"); return messagesMap; } /** * 跳转到编辑页面 * * @return */ @GetMapping(value = "/stree/edit/{id}") public String editStree(@PathVariable("id") int id, ModelMap modelMap) { Street stree = streeService.findById(id); log.info("跳转到内容编辑页面!id = {}", id); modelMap.put("stree", stree); return BASE_SUPER_PATH + "/stree_edit"; } @OperationLog(value = "街道删除") @ResponseBody @PutMapping(value = "/stree/delete") public ResponseMessage deleteStree(@RequestParam("ids") String ids) { Street stree = streeService.findById(Integer.parseInt(ids)); if (null == stree) { return ResponseMessage.error("未找到相应的街道"); } //若街道下面有园区,则不能删。 Integer buildCount = buildService.findBuildCountByStreet(Integer.parseInt(ids)); if(buildCount>0){ return ResponseMessage.error("删除失败!该街道下存在园区,不能删除。"); } stree.setDel_flag(true); Boolean flag = streeService.updateStree(stree); if (flag) { return ResponseMessage.success("删除成功!"); } else { return ResponseMessage.error("删除失败!"); } } @OperationLog(value = "园区类型删除") @ResponseBody @PutMapping(value = "/buildType/delete") public ResponseMessage deleteBuildType(@RequestParam("ids") String ids) { BuildType bt = buildTypeService.findById(Integer.parseInt(ids)); if (null == bt) { return ResponseMessage.error("未找到相应的园区类型"); } //若园区类型下面有园区,则不能删除。 Integer buildCount = buildService.findCountByType(Integer.parseInt(ids)); if(buildCount>0){ return ResponseMessage.error("删除失败!该类型下存在园区,不能删除。"); } bt.setDel_flag(true); Boolean flag = buildTypeService.updateBuildType(bt); if (flag) { return ResponseMessage.success("删除成功!"); } else { return ResponseMessage.error("删除失败!"); } } @OperationLog(value = "园区删除") @ResponseBody @PutMapping(value = "/build/delete") public ResponseMessage deleteBuild(@RequestParam("ids") String ids) { BuildInfo b = buildService.findById(Integer.parseInt(ids)); if (null == b) { return ResponseMessage.error("未找到相应的园区"); } //若园区下面有企业,则不能删。 Integer companyCount = companyService.findAllCuntCompanyByBuildId(Integer.parseInt(ids)); if(companyCount>0){ return ResponseMessage.error("删除失败!该园区下存在企业,不能删除。"); } b.setDel_flag(true); Boolean flag = buildService.updateBuild(b); if (flag) { return ResponseMessage.success("删除成功!"); } else { return ResponseMessage.error("删除失败!"); } } @GetMapping(value = "/buildTypeList") public String buildTypeList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, String keyword, ModelMap modelMap) throws Exception { PageInfo pageInfo = buildTypeService.findPage(pageNum, PAGESIZE, keyword, Constant.DictType.BUILD); modelMap.put("pageInfo", pageInfo); modelMap.put("keyword", keyword); return BASE_SUPER_PATH + "/buildtype_list"; } @GetMapping(value = "/buildType/add") public String addBuildTypePage(ModelMap modelMap) { return BASE_SUPER_PATH + "/buildtype_add"; } @OperationLog(value = "园区类型保存") @ResponseBody @PostMapping(value = "/buildType/save") public ModelMap saveBuildType(BuildType bt) throws Exception { ModelMap messagesMap = new ModelMap(); if(IsTooFrequently()) { messagesMap.put("status", FAILURE); messagesMap.put("message", "操作过于频繁,请稍后再试!"); return messagesMap; } Boolean flag = false; bt.setOpt_type(Constant.DictType.BUILD); if (bt.getId() == null) { flag = buildTypeService.saveBuildType(bt); } else { flag = buildTypeService.updateBuildType(bt); } if (flag) { messagesMap.put("status", SUCCESS); messagesMap.put("message", "操作成功!"); return messagesMap; } messagesMap.put("status", FAILURE); messagesMap.put("message", "操作失败!"); return messagesMap; } /** * 跳转到编辑页面 * * @return */ @GetMapping(value = "/buildType/edit/{id}") public String editBuildType(@PathVariable("id") int id, ModelMap modelMap) { BuildType buildType = buildTypeService.findById(id); modelMap.put("buildType", buildType); return BASE_SUPER_PATH + "buildtype_edit"; } @OperationLog(value = "企业类型删除") @ResponseBody @DeleteMapping(value = "/companyType/delete/{id}") public ResponseMessage deleteStreetType(@PathVariable("id") Integer id) { BuildType bt = buildTypeService.findById(id); if (null == bt) { return ResponseMessage.error("未找到相应的企业类型"); } //若园区类型下面有园区,则不能删除。 Integer buildCount = companyService.countByType(id); if(buildCount>0){ return ResponseMessage.error("删除失败!该类型下存在企业,不能删除。"); } bt.setDel_flag(true); Boolean flag = buildTypeService.updateBuildType(bt); if (flag) { return ResponseMessage.success("删除成功!"); } else { return ResponseMessage.error("删除失败!"); } } @GetMapping(value = "/companyTypeList") public String streetTypeList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, String keyword, ModelMap modelMap) throws Exception { PageInfo pageInfo = buildTypeService.findPage(pageNum, PAGESIZE, keyword,Constant.DictType.COMPANY); modelMap.put("pageInfo", pageInfo); modelMap.put("keyword", keyword); return BASE_SUPER_PATH + "/company_type_list"; } @GetMapping(value = "/companyType/add") public String companyTypeAdd() { return BASE_SUPER_PATH + "/company_type_add"; } @OperationLog(value = "园区类型保存") @ResponseBody @PostMapping(value = "/companyTypeSave") public ModelMap companyTypeSave(BuildType bt) throws Exception { ModelMap messagesMap = new ModelMap(); if(IsTooFrequently()) { messagesMap.put("status", FAILURE); messagesMap.put("message", "操作过于频繁,请稍后再试!"); return messagesMap; } Boolean flag = false; bt.setOpt_type(Constant.DictType.COMPANY); if (bt.getId() == null) { flag = buildTypeService.saveBuildType(bt); } else { flag = buildTypeService.updateBuildType(bt); } if (flag) { messagesMap.put("status", SUCCESS); messagesMap.put("message", "操作成功!"); return messagesMap; } messagesMap.put("status", FAILURE); messagesMap.put("message", "操作失败!"); return messagesMap; } /** * 跳转到编辑页面 * * @return */ @GetMapping(value = "/companyType/edit/{id}") public String companyTypeEdit(@PathVariable("id") int id, ModelMap modelMap) { BuildType buildType = buildTypeService.findById(id); modelMap.put("companyType", buildType); return BASE_SUPER_PATH + "company_type_edit"; } @GetMapping(value = "/buildList") public String buildList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, String keyword, String street_id, String type, ModelMap modelMap) throws Exception { HashMap param = new HashMap<>(); param.put("keyWord", keyword); param.put("street_id", street_id); param.put("type", type); PageInfo pageInfo = buildService.findSPage(pageNum, PAGESIZE, param); modelMap.put("pageInfo", pageInfo); modelMap.put("keyword", keyword); modelMap.put("street_id",StringUtils.isBlank(street_id)?null:Integer.parseInt(street_id)); modelMap.put("type",StringUtils.isBlank(type)?null:Integer.parseInt(type)); getBuildPageInit(modelMap); return BASE_SUPER_PATH + "/build_list"; } /** * 获取园区页面初始化下拉框信息 * * @param modelMap */ private void getBuildPageInit(ModelMap modelMap) { modelMap.addAttribute("streeList", streeService.findList()); modelMap.addAttribute("buildTypeList", buildTypeService.findList(Constant.DictType.BUILD)); } @GetMapping(value = "/build/add") public String addBuildPage(ModelMap modelMap) { getBuildPageInit(modelMap); return BASE_SUPER_PATH + "/build_add"; } /** * 跳转到编辑页面 * * @return */ @GetMapping(value = "/build/edit/{id}") public String editBuild(@PathVariable("id") int id, ModelMap modelMap) { getBuildPageInit(modelMap); BuildInfo build = buildService.findById(id); modelMap.put("build", build); return BASE_SUPER_PATH + "build_edit"; } @OperationLog(value = "园区信息修改") @ResponseBody @PostMapping(value = "/build/save") public ModelMap saveBuild(BuildInfo b) throws Exception { ModelMap messagesMap = new ModelMap(); if(IsTooFrequently()) { messagesMap.put("status", FAILURE); messagesMap.put("message", "操作过于频繁,请稍后再试!"); return messagesMap; } Boolean flag = false; if (b.getId() == null) { flag = buildService.saveBuild(b); } else { flag = buildService.updateBuild(b); } if (flag) { messagesMap.put("status", SUCCESS); messagesMap.put("message", "操作成功!"); return messagesMap; } messagesMap.put("status", FAILURE); messagesMap.put("message", "操作失败!"); return messagesMap; } /** * 检验街道名是否存在 * * @param name * @return */ @ResponseBody @GetMapping(value = "/isExistStreet") public Boolean isExistStreet(String id, String name) throws Exception { boolean flag = true; log.debug("检验街道名是否存在参数! id= {}, name= {}", id, name); Street street = streeService.getStreet(name); if (null != street) { if (StringUtils.isBlank(id)) { flag = false; } else { if (street.getId() != (Integer.parseInt(id))) { flag = false; } } } log.info("检验街道名是否存在结果! flag = {}", flag); return flag; } /** * 检验园区名是否存在 * * @param name * @return */ @ResponseBody @GetMapping(value = "/isExistBuild") public Boolean isExistBuild(String id, String name) throws Exception { boolean flag = true; log.debug("检验园区名是否存在参数! id= {}, name= {}", id, name); BuildInfo buildInfo= buildService.getBuildInfo(name); if (null != buildInfo) { if (StringUtils.isBlank(id)) { flag = false; } else { if (buildInfo.getId() != (Integer.parseInt(id))) { flag = false; } } } log.info("检验园区名是否存在结果! flag = {}", flag); return flag; } /** * 检验园区类型是否存在 * * @param name * @return */ @ResponseBody @GetMapping(value = "/isExistBuildType") public Boolean isExistBuildType(String id, String name) throws Exception { boolean flag = true; log.debug("检验园区类型是否存在参数! id= {}, name= {}", id, name); BuildType buildInfo= buildTypeService.getBuildInfo(name,Constant.DictType.BUILD); if (null != buildInfo) { if (StringUtils.isBlank(id)) { flag = false; } else { if (buildInfo.getId() != (Integer.parseInt(id))) { flag = false; } } } log.info("检验园区名是否存在结果! flag = {}", flag); return flag; } /** * 检验企业类型是否存在 * * @param name * @return */ @ResponseBody @GetMapping(value = "/isExistCompanyType") public Boolean isExistCompanyType(String id, String name) throws Exception { boolean flag = true; log.debug("检验企业类型是否存在! id= {}, name= {}", id, name); BuildType buildInfo= buildTypeService.getBuildInfo(name,Constant.DictType.COMPANY); if (null != buildInfo) { if (StringUtils.isBlank(id)) { flag = false; } else { if (buildInfo.getId() != (Integer.parseInt(id))) { flag = false; } } } log.info("检验企业类型是否存在结果! flag = {}", flag); return flag; } /** * 更新街道状态 * * @param id * @return */ @OperationLog(value = "更新街道状态") @ResponseBody @PostMapping(value = "/status/{id}") public ResponseMessage status(@PathVariable Integer id, @RequestParam("isLock") Boolean isLock) throws Exception { log.debug("更新街道状态! ids = {}", id); Street street = new Street(); street.setId(id); street.setIs_start(isLock); if(1==streeService.updateSelective(street)){ userService.updateStreetIsStart(id, null, isLock); return ResponseMessage.success("更新状态成功!"); } return ResponseMessage.error("更新状态失败!"); } /*********************数据字典**********************/ /** * 数据字典类型列表展示 * * @param pageNum * @param keyword * @param modelMap * @return * @throws Exception */ @GetMapping(value = "/dictionaryTypeList") public String dictionaryTypeList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, String keyword, ModelMap modelMap) throws Exception { PageInfo pageInfo = dictionaryTypeService.findPage(pageNum, PAGESIZE, keyword); modelMap.put("pageInfo", pageInfo); modelMap.put("keyword", keyword); return BASE_SUPER_PATH + "dictionary/dictionary_type_list"; } @GetMapping(value = "/dictionaryType/add") public String addDictionaryTypePage(ModelMap modelMap) { return BASE_SUPER_PATH + "dictionary/dictionary_type_add"; } @GetMapping(value = "/dictionaryType/edit/{id}") public String editDictionaryTypePage(@PathVariable("id") int id,ModelMap modelMap) { DictionaryType dictionaryType = dictionaryTypeService.findById(id); modelMap.put("dictionaryType", dictionaryType); return BASE_SUPER_PATH + "dictionary/dictionary_type_edit"; } @OperationLog(value = "数据字典类型保存") @ResponseBody @PostMapping(value = "/dictionaryType/save") public ResponseMessage saveDictionaryType(DictionaryType type) throws Exception { if(IsTooFrequently()) { return ResponseMessage.success("操作过于频繁,请稍后再试!"); } Boolean flag = false; if (type.getId() == null) { flag = dictionaryTypeService.saveDictionaryType(type); } else { flag = dictionaryTypeService.updateDictionaryType(type); } if (flag) { return ResponseMessage.success("操作成功!"); } return ResponseMessage.success("操作失败!"); } @OperationLog(value = "数据字典类型删除") @ResponseBody @DeleteMapping(value = "/dictionaryType/delete/{id}") public ResponseMessage deleteDictionaryType(@PathVariable("id") int id,ModelMap modelMap) { DictionaryType type = dictionaryTypeService.findById(id); if (null == type) { return ResponseMessage.error("未找到相应的数据类型"); } type.setDel_flag(true); Boolean flag = dictionaryTypeService.updateDictionaryType(type); if (flag) { return ResponseMessage.success("删除成功!"); } else { return ResponseMessage.error("删除失败!"); } } /** * 检验数据类型是否存在 * @param * @param name * @return */ @ResponseBody @GetMapping(value = "/isExistDictionaryType") public Boolean isExistDictionaryType(String id, String name) throws Exception { boolean flag = true; log.debug("检验数据类型是否存在参数! id= {}, name= {}", id, name); DictionaryType dictionaryType= dictionaryTypeService.getDictionaryType(name); if (null != dictionaryType) { if (StringUtils.isBlank(id)) { flag = false; } else { if (dictionaryType.getId() != (Integer.parseInt(id))) { flag = false; } } } log.info("检验数据类型是否存在结果! flag = {}", flag); return flag; } /** * 数据字典条目列表展示 * * @param pageNum * @param keyword * @param modelMap * @return * @throws Exception */ @GetMapping(value = "/dictionaryItemList") public String dictionaryItemList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, String keyword, ModelMap modelMap,Integer typeId) throws Exception { Example example = new Example(DictionaryType.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", 0); criteria.andEqualTo("is_active", 1); List typeList = dictionaryTypeService.selectByExample(example); modelMap.put("typeList", typeList); if(null == typeId) { if(null != typeList && typeList.size()>0) { typeId = typeList.get(0).getId(); modelMap.put("typeId", typeList.get(0).getId()); } } PageInfo pageInfo = dictionaryItemService.findPageByType(pageNum, PAGESIZE, keyword,typeId); modelMap.put("typeId", typeId); modelMap.put("pageInfo", pageInfo); modelMap.put("keyword", keyword); return BASE_SUPER_PATH + "dictionary/dictionary_item_list"; } /** * 检验数据类型条目是否存在 * @param * @param name * @return */ @ResponseBody @GetMapping(value = "/isExistDictionaryItem") public Boolean isExistDictionaryItem(String id, String name,String value,Integer typeId) throws Exception { boolean flag = true; log.debug("检验数据类型条目是否存在参数! id= {}, name= {}", id, name); DictionaryItem dictionaryItem= dictionaryItemService.getDictionaryItem(name,value,typeId); if (null != dictionaryItem) { if (StringUtils.isBlank(id)) { flag = false; } else { if (dictionaryItem.getId() != (Integer.parseInt(id))) { flag = false; } } } log.info("检验数据类型条目是否存在结果! flag = {}", flag); return flag; } @GetMapping(value = "/dictionaryItem/add/{typeId}") public String addDictionaryItemPage(@PathVariable("typeId") int typeId,ModelMap modelMap) { modelMap.put("typeId", typeId); return BASE_SUPER_PATH + "dictionary/dictionary_item_add"; } @GetMapping(value = "/dictionaryItem/edit/{id}") public String editDictionaryItemPage(@PathVariable("id") int id,ModelMap modelMap) { DictionaryItem dictionaryItem = dictionaryItemService.findById(id); modelMap.put("dictionaryItem", dictionaryItem); return BASE_SUPER_PATH + "dictionary/dictionary_item_edit"; } @OperationLog(value = "数据字典类型条目保存") @ResponseBody @PostMapping(value = "/dictionaryItem/save") public ResponseMessage saveDictionaryItem(DictionaryItem item) throws Exception { if(IsTooFrequently()) { return ResponseMessage.success("操作过于频繁,请稍后再试!"); } Boolean flag = false; if (item.getId() == null) { flag = dictionaryItemService.saveDictionaryItem(item); } else { flag = dictionaryItemService.updateDictionaryItem(item); } if (flag) { return ResponseMessage.success("操作成功!"); } return ResponseMessage.success("操作失败!"); } @OperationLog(value = "数据字典类型条目删除") @ResponseBody @DeleteMapping(value = "/dictionaryItem/delete/{id}") public ResponseMessage deleteDictionaryItem(@PathVariable("id") int id,ModelMap modelMap) { DictionaryItem item = dictionaryItemService.findById(id); if (null == item) { return ResponseMessage.error("未找到相应的数据类型条目"); } item.setDel_flag(true); Boolean flag = dictionaryItemService.updateDictionaryItem(item); if (flag) { return ResponseMessage.success("删除成功!"); } else { return ResponseMessage.error("删除失败!"); } } /*********************模板管理**********************/ /** * 模板管理列表展示 * * @param pageNum * @param keyword * @param modelMap * @return * @throws Exception */ @GetMapping(value = "/templateList") public String templateList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, String keyword, ModelMap modelMap) throws Exception { PageInfo