CompanyController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. package platform.modules.build.web;
  2. import com.github.pagehelper.PageInfo;
  3. import org.apache.commons.lang3.StringUtils;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Controller;
  6. import org.springframework.ui.ModelMap;
  7. import org.springframework.web.bind.annotation.*;
  8. import platform.common.Constant;
  9. import platform.common.annotation.OperationLog;
  10. import platform.common.base.controller.BaseController;
  11. import platform.common.base.model.DictionaryItem;
  12. import platform.common.base.service.DictionaryItemService;
  13. import platform.common.util.ShiroUtils;
  14. import platform.modules.build.DTO.CompanyDto;
  15. import platform.modules.build.DTO.CompanyFeeDto;
  16. import platform.modules.build.DTO.MaintenanceDto;
  17. import platform.modules.build.entity.BuildInfo;
  18. import platform.modules.build.entity.Company;
  19. import platform.modules.build.entity.Maintenance;
  20. import platform.modules.build.service.BuildInfoService;
  21. import platform.modules.build.service.CompanyContactService;
  22. import platform.modules.build.service.CompanyService;
  23. import platform.modules.build.service.MaintenanceService;
  24. import platform.modules.company.service.CompanyBuildingStreetService;
  25. import platform.modules.company.service.CompanyInfoManageService;
  26. import platform.modules.government.dto.NotifyDto;
  27. import platform.modules.government.entity.BuildType;
  28. import platform.modules.government.entity.Notify;
  29. import platform.modules.government.entity.Street;
  30. import platform.modules.government.entity.User;
  31. import platform.modules.government.service.BuildTypeService;
  32. import platform.modules.government.service.NotifyService;
  33. import platform.modules.government.service.StreetService;
  34. import platform.modules.government.service.UserService;
  35. import platform.modules.sys.web.ResponseMessage;
  36. import java.util.List;
  37. /**
  38. * 企业信息Controller
  39. *
  40. * @author lhf
  41. * @version 2017-10-26
  42. */
  43. @Controller
  44. @RequestMapping(value = "/build/company")
  45. public class CompanyController extends BaseController {
  46. @Autowired
  47. private CompanyService companyService;
  48. @Autowired
  49. private MaintenanceService maintenanceService;
  50. @Autowired
  51. private NotifyService notifyService;
  52. @Autowired
  53. private BuildTypeService buildTypeService;
  54. @Autowired
  55. private BuildInfoService buildInfoService;
  56. @Autowired
  57. private StreetService streetService;
  58. @Autowired
  59. private CompanyContactService companyContactService;
  60. @Autowired
  61. private CompanyBuildingStreetService companyBuildingStreetService;
  62. @Autowired
  63. private DictionaryItemService dictionaryItemService;
  64. @Autowired
  65. private UserService userService;
  66. @GetMapping(value = "/list")
  67. public String list(
  68. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  69. String keyword, ModelMap modelMap, String item_selected) throws Exception {
  70. try {
  71. log.debug("分页查询公司列表参数! pageNum = {}, keyword = {}", pageNum, keyword);
  72. PageInfo<Company> pageInfo = companyService.findPage(pageNum, PAGESIZE, keyword, null, new CompanyDto());
  73. log.info("分页查询公司列表结果! pageInfo = {}", pageInfo);
  74. modelMap.put("pageInfo", pageInfo);
  75. modelMap.put("keyword", keyword);
  76. modelMap.put("item_selected", item_selected);
  77. } catch (Exception e) {
  78. e.printStackTrace();
  79. }
  80. return BASE_BUILD_PATH + "company_list";
  81. }
  82. /**
  83. * 跳转到公司添加页面
  84. *
  85. * @return
  86. */
  87. @GetMapping(value = "/add")
  88. public String add(ModelMap modelMap) {
  89. modelMap.put("companyTypeList", buildTypeService.findList(Constant.DictType.COMPANY));
  90. log.info("跳转到公司添加页面!");
  91. return BASE_BUILD_PATH + "company_add";
  92. }
  93. /**
  94. * 添加公司
  95. *
  96. * @param content
  97. * @return
  98. */
  99. @OperationLog(value = "添加公司")
  100. @ResponseBody
  101. @PostMapping(value = "/save")
  102. public ModelMap saveCompany(Company content) throws Exception {
  103. ModelMap messagesMap = new ModelMap();
  104. if (IsTooFrequently()) {
  105. messagesMap.put("status", FAILURE);
  106. messagesMap.put("message", "操作过于频繁,请稍后再试!");
  107. return messagesMap;
  108. }
  109. log.debug("添加公司参数! content = {}", content);
  110. Boolean flag = companyService.saveCompany(content);
  111. if (flag) {
  112. log.info("添加公司成功! content = {}", content.getId());
  113. messagesMap.put("status", SUCCESS);
  114. messagesMap.put("message", "添加成功!");
  115. return messagesMap;
  116. }
  117. messagesMap.put("status", FAILURE);
  118. messagesMap.put("message", "添加失败!");
  119. return messagesMap;
  120. }
  121. /**
  122. * 跳转到公司编辑页面
  123. *
  124. * @return
  125. */
  126. @GetMapping(value = "/edit/{id}")
  127. public String edit(@PathVariable("id") int id, ModelMap modelMap) {
  128. Company company = companyService.findById(id);
  129. log.info("跳转到公司编辑页面!id = {}", id);
  130. modelMap.put("company", company);
  131. if (null != company) {
  132. company.setCompanyContacts(companyContactService.findByCompanyId(id));
  133. }
  134. modelMap.put("companyTypeList", buildTypeService.findList(Constant.DictType.COMPANY));
  135. return BASE_BUILD_PATH + "company_edit";
  136. }
  137. /**
  138. * 跳转到公司查看页面
  139. *
  140. * @return
  141. */
  142. @GetMapping(value = "/check/{id}")
  143. public String check(@PathVariable("id") int id, ModelMap modelMap) {
  144. Company company = companyService.findById(id);
  145. log.info("跳转到公司查看页面!id = {}", id);
  146. BuildType buildType = buildTypeService.findById(company.getType_id());
  147. if (null != buildType) {
  148. company.setType_name(buildType.getType());
  149. }
  150. if (null != company) {
  151. company.setCompanyContacts(companyContactService.findByCompanyId(id));
  152. }
  153. modelMap.put("company", company);
  154. return BASE_BUILD_PATH + "company_check";
  155. }
  156. /**
  157. * 更新公司信息
  158. *
  159. * @param id id
  160. * @return
  161. */
  162. @OperationLog(value = "编辑公司")
  163. @ResponseBody
  164. @PutMapping(value = "/updateCompany/{id}")
  165. public ResponseMessage updateCompany(@PathVariable("id") int id, Company content) throws Exception {
  166. ModelMap messagesMap = new ModelMap();
  167. log.debug("编辑公司参数! id= {}, content = {}", id, content);
  168. if (IsTooFrequently()) {
  169. return ResponseMessage.success("操作过于频繁,请稍后再试!");
  170. }
  171. Company u = companyService.findById(id);
  172. if (null == u) {
  173. log.info("编辑公司不存在! id = {}", id);
  174. return ResponseMessage.error("编辑公司不存在!");
  175. }
  176. Boolean flag = companyService.updateCompany(content);
  177. if (flag) {
  178. log.info("编辑公司成功! id= {}, content = {}", id, content);
  179. return ResponseMessage.success("编辑成功");
  180. }
  181. return ResponseMessage.error("编辑失败!");
  182. }
  183. /**
  184. * 批量删除
  185. *
  186. * @param ids
  187. * @return
  188. */
  189. @OperationLog(value = "批量删除")
  190. @ResponseBody
  191. @PutMapping(value = "/deleteBatch")
  192. public ResponseMessage deleteBatch(@RequestParam(value = "ids[]") String[] ids) throws Exception {
  193. if (null == ids) {
  194. log.info("批量删除公司不存在! ids = {}", ids);
  195. return ResponseMessage.success("批量删除公司不存在");
  196. }
  197. for (String id : ids) {
  198. Company company = new Company();
  199. company.setId(Integer.parseInt(id));
  200. company.setDel_flag(true);
  201. companyService.updateCompany(company);
  202. }
  203. return ResponseMessage.success("删除成功");
  204. }
  205. /**
  206. * 启用
  207. *
  208. * @param ids
  209. * @return
  210. */
  211. @OperationLog(value = "启用")
  212. @ResponseBody
  213. @PutMapping(value = "/startBatch")
  214. public ResponseMessage startBatch(@RequestParam(value = "ids[]") String[] ids) throws Exception {
  215. if (IsTooFrequently()) {
  216. return ResponseMessage.success("操作过于频繁,请稍后再试!");
  217. }
  218. if (null == ids) {
  219. log.info("批量启用公司不存在! ids = {}", ids);
  220. return ResponseMessage.success("批量启用公司不存在");
  221. }
  222. for (String id : ids) {
  223. Company company = new Company();
  224. company.setId(Integer.parseInt(id));
  225. company.setIs_start(true);
  226. companyService.updateSelective(company);
  227. }
  228. return ResponseMessage.success("启用成功");
  229. }
  230. /**
  231. * 禁用
  232. *
  233. * @param ids
  234. * @return
  235. */
  236. @OperationLog(value = "禁用")
  237. @ResponseBody
  238. @PutMapping(value = "/stopBatch")
  239. public ResponseMessage stopBatch(@RequestParam(value = "ids[]") String[] ids) throws Exception {
  240. if (IsTooFrequently()) {
  241. return ResponseMessage.success("操作过于频繁,请稍后再试!");
  242. }
  243. if (null == ids) {
  244. log.info("批量启用公司不存在! ids = {}", ids);
  245. return ResponseMessage.success("批量启用公司不存在");
  246. }
  247. for (String id : ids) {
  248. Company company = new Company();
  249. company.setId(Integer.parseInt(id));
  250. company.setIs_start(false);
  251. companyService.updateSelective(company);
  252. }
  253. return ResponseMessage.success("禁用成功");
  254. }
  255. /**
  256. * 检验公司名是否存在
  257. *
  258. * @param company_name
  259. * @return
  260. */
  261. @ResponseBody
  262. @GetMapping(value = "/isExist")
  263. public Boolean isExist(String company_name, String id) throws Exception {
  264. boolean flag = true;
  265. log.debug("检验公司名是否存在参数! id= {}, companyname= {}", id, company_name);
  266. Company record = companyService.findByCompanyName(company_name);
  267. if (null != record) {
  268. if (StringUtils.isBlank(id)) {
  269. flag = false;
  270. } else {
  271. if (record.getId() != (Integer.parseInt(id))) {
  272. flag = false;
  273. }
  274. }
  275. }
  276. log.info("检验公司名是否存在结果! flag = {}", flag);
  277. return flag;
  278. }
  279. /**
  280. * 企业PC端费用查询
  281. *
  282. * @param pageNum
  283. * @param modelMap
  284. * @return
  285. * @throws Exception
  286. */
  287. @GetMapping(value = "/feeList")
  288. public String feeList(
  289. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  290. String fee_type, String status, ModelMap modelMap) throws Exception {
  291. try {
  292. log.debug("分页查询公司列表参数! pageNum = {}, status = {}, fee_type = {}", pageNum, status, fee_type);
  293. PageInfo<CompanyFeeDto> pageInfo = companyService.findCompanyFeePage(pageNum, PAGESIZE, status, fee_type);
  294. log.info("分页查询公司列表结果! pageInfo = {}", pageInfo);
  295. modelMap.put("pageInfo", pageInfo);
  296. modelMap.put("fee_type", fee_type);
  297. modelMap.put("status", status);
  298. } catch (Exception e) {
  299. e.printStackTrace();
  300. }
  301. return BASE_BUILD_PATH + "company_fee_list";
  302. }
  303. /**
  304. * 企业PC端首页
  305. *
  306. * @param modelMap
  307. * @return
  308. */
  309. @GetMapping(value = "/index")
  310. public String index(ModelMap modelMap) {
  311. try {
  312. Integer company_id = ShiroUtils.getUserEntity().getCompany_id();
  313. //费用提醒,获取未缴费费用
  314. int feeCount = 5;
  315. CompanyFeeDto companyFeeDto = new CompanyFeeDto(company_id, feeCount, 0);
  316. List<CompanyFeeDto> feeList = companyService.findLatestCompnayFee(companyFeeDto);
  317. modelMap.put("feeList", feeList);
  318. //通知公告
  319. int notifyCount = 5;
  320. NotifyDto notifyDto = new NotifyDto();
  321. notifyDto.setCompany_id(company_id);
  322. notifyDto.setCount(notifyCount);
  323. // todo
  324. List<Notify> latestNotifyList = notifyService.findNotifyList(notifyDto);
  325. modelMap.put("latestNotifyList", latestNotifyList);
  326. //维修跟踪
  327. int maintenanceCount = 5;
  328. MaintenanceDto maintenanceDto = new MaintenanceDto(null, company_id, maintenanceCount);
  329. List<Maintenance> maintenanceList = maintenanceService.findLatestMaintenance(maintenanceDto);
  330. modelMap.put("maintenanceList", maintenanceList);
  331. } catch (Exception e) {
  332. // TODO Auto-generated catch block
  333. e.printStackTrace();
  334. }
  335. return BASE_BUILD_PATH + "companyIndex";
  336. }
  337. /**
  338. * 企业PC端账号信息
  339. *
  340. * @param modelMap
  341. * @return
  342. */
  343. @GetMapping(value = "/companyInfo")
  344. public String companyInfo(ModelMap modelMap) {
  345. Integer company_id = ShiroUtils.getUserEntity().getCompany_id();
  346. Company company = companyService.findById(company_id);
  347. if (null != company) {
  348. if (null != company.getBuild_id()) {
  349. BuildInfo buildInfo = buildInfoService.findById(company.getBuild_id());
  350. if (null != buildInfo) {
  351. company.setBuild_name(buildInfo.getName());
  352. }
  353. }
  354. Street street = streetService.findById(company.getStreet_id());
  355. if (null != street) {
  356. company.setStreet_name(street.getName());
  357. }
  358. company.setCompanyContacts(companyContactService.findByCompanyId(company_id));
  359. company.setBuildingStreets(companyBuildingStreetService.findByCompanyId(company_id));
  360. }
  361. modelMap.put("company", company);
  362. List<Street> streetList = streetService.findList();
  363. modelMap.addAttribute("streetList", streetList);
  364. if (null != company.getStreet_id()) {
  365. modelMap.addAttribute("buildList", buildInfoService.findListByStreet(company.getStreet_id()));
  366. }
  367. //查询企业性质
  368. List<DictionaryItem> companyTypeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.COMPANY_TYPE);
  369. modelMap.put("companyTypeList", companyTypeList);
  370. //查询币种单位数据
  371. List<DictionaryItem> itemList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.CURRENCY_UNIT);
  372. modelMap.put("itemList", itemList);
  373. //查询行业类型
  374. List<DictionaryItem> industryTypeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.INDUSTRY_TYPE);
  375. modelMap.put("industryTypeList", industryTypeList);
  376. User user = ShiroUtils.getUserEntity();
  377. user.setFist_login(2);
  378. userService.updateSelective(user);
  379. return BASE_BUILD_PATH + "companyInfo";
  380. }
  381. /**
  382. * 企业PC端用户账号信息
  383. *
  384. * @param modelMap
  385. * @return
  386. */
  387. @GetMapping(value = "/companyUserInfo")
  388. public String companyUserInfo(ModelMap modelMap) {
  389. User user = ShiroUtils.getUserEntity();
  390. modelMap.put("user", user);
  391. return BASE_COMPANY_PATH + "accountInfo/companyUserInfo";
  392. }
  393. }