package com.cyx.wechat; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.cyx.common.annotation.Log; import com.cyx.common.core.controller.BaseController; import com.cyx.common.core.domain.AjaxResult; import com.cyx.common.core.domain.entity.SysDept; import com.cyx.common.core.domain.entity.SysUser; import com.cyx.common.core.page.TableDataInfo; import com.cyx.common.enums.BusinessType; import com.cyx.common.utils.StringUtils; import com.cyx.system.service.ISysDeptService; import com.cyx.system.service.ISysUserService; import com.cyx.web.base.domain.TAmentCommitHis; import com.cyx.web.base.domain.TAmentPartyAffairs; import com.cyx.web.base.domain.TAmentPersonnel; import com.cyx.web.base.domain.TAmentReviewedHis; import com.cyx.web.base.service.ITAmentCommitHisService; import com.cyx.web.base.service.ITAmentPartyAffairsService; import com.cyx.web.base.service.ITAmentPersonnelService; import com.cyx.web.base.service.ITAmentReviewedHisService; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Controller @RequestMapping("/wx/index") public class WechatController extends BaseController { @Resource private ITAmentPartyAffairsService partyAffairsService; @Autowired private ITAmentCommitHisService commitHisService; @Autowired private ITAmentReviewedHisService reviewedHisService; @Autowired private ISysUserService userService; @Autowired private ISysDeptService deptService; @Autowired private ITAmentPersonnelService personnelService; /** * 微信小程序获取openId * @param code * @return */ @GetMapping(value = "/getUserInfo") public AjaxResult getUserInfo(String code){ SysUser user = userService.selectUserById(1L); UsernamePasswordToken token = new UsernamePasswordToken(user.getUserName(), user.getPassword(), true); Subject subject = SecurityUtils.getSubject(); try { subject.login(token); return success(); } catch (AuthenticationException e) { String msg = "用户或密码错误"; if (StringUtils.isNotEmpty(e.getMessage())) { msg = e.getMessage(); } return error(msg); } } /** * 部门列表 * @param dept * @return */ // @RequiresPermissions("base:dept:list") @PostMapping("/deptList") @ResponseBody public AjaxResult deptList(@RequestBody SysDept dept) { return AjaxResult.success(deptService.selectDeptList(dept)); } /** * 人员列表 * @param personnel * @return */ // @RequiresPermissions("base:personnel:list") @PostMapping("/personList") @ResponseBody public AjaxResult personList(@RequestBody TAmentPersonnel personnel) { return AjaxResult.success(personnelService.selectTAmentPersonnelList(personnel)); } // @RequiresPermissions("base:affairs:list") @PostMapping("/queryTree") @ResponseBody public AjaxResult queryTree(@RequestBody TAmentPartyAffairs affairs) { List list = partyAffairsService.selectTAmentPartyAffairsList(affairs); Map> targetMap = list.stream().collect(Collectors.groupingBy(TAmentPartyAffairs::getTarget)); JSONArray array = new JSONArray(); // 循环target for (Map.Entry> entry : targetMap.entrySet()) { JSONObject object = new JSONObject(); object.put("text",entry.getKey()); // 同一target List list1 = entry.getValue(); JSONArray array1 = new JSONArray(); list1.forEach(l->{ JSONObject object1 = new JSONObject(); object1.put("text",l.getDemand()); object1.put("id",l.getId()); array1.add(object1); }); object.put("children",array1); array.add(object); // // 循环demand // Map> detailMap = list1.stream().collect(Collectors.groupingBy(TAmentPartyAffairs::getDemand)); // for (Map.Entry> entry1 : detailMap.entrySet()){ // JSONObject object1 = new JSONObject(); // object.put("name",entry1.getKey()); // List de = entry.getValue(); // } // object.put("name",entry.getKey()); } return AjaxResult.success(array); } /** * 任务预警 */ // @RequiresPermissions("base:affairs:list") @PostMapping("/queryList") @ResponseBody public TableDataInfo queryList(@RequestBody TAmentPartyAffairs tAmentPartyAffairs) { startPage(tAmentPartyAffairs.getPageNum(),tAmentPartyAffairs.getPageSize()); List list = partyAffairsService.selectTAmentPartyAffairsList(tAmentPartyAffairs); return getDataTable(list); } /** * 提交附件 */ // @RequiresPermissions("base:affairs:edit") @Log(title = "党务", businessType = BusinessType.UPDATE) @PostMapping("/commit") @ResponseBody public AjaxResult commit(@RequestBody TAmentPartyAffairs tAmentPartyAffairs) { TAmentCommitHis his = new TAmentCommitHis(); his.setPer(tAmentPartyAffairs.getHeader()); his.setDept(tAmentPartyAffairs.getDeptName()); his.setTarget(tAmentPartyAffairs.getShotName()); his.setCommitTime(new Date()); his.setRemark(tAmentPartyAffairs.getRemark()); his.setFiles(tAmentPartyAffairs.getFiles()); tAmentPartyAffairs.setStatus("2"); commitHisService.insertTAmentCommitHis(his); tAmentPartyAffairs.setCommitId(his.getId()); return toAjax(partyAffairsService.updateTAmentPartyAffairs(tAmentPartyAffairs)); } /** * 审核 */ // @RequiresPermissions("base:affairs:edit") @Log(title = "党务", businessType = BusinessType.UPDATE) @PostMapping("/reviewedSave") @ResponseBody public AjaxResult reviewedSave(@RequestBody TAmentPartyAffairs tAmentPartyAffairs) { TAmentPartyAffairs one = partyAffairsService.selectTAmentPartyAffairsById(tAmentPartyAffairs.getId()); TAmentReviewedHis his = new TAmentReviewedHis(); his.setPer(tAmentPartyAffairs.getReviewer()); his.setReviewedTime(new Date()); int before = 0; if (null != one && null != one.getNowScore()){ before = Integer.parseInt(one.getNowScore()); } int reviewScore = Integer.parseInt(tAmentPartyAffairs.getNowScore()); his.setScore(tAmentPartyAffairs.getNowScore()); his.setRemark(tAmentPartyAffairs.getRemark()); reviewedHisService.insertTAmentReviewedHis(his); tAmentPartyAffairs.setReviewedId(his.getId()); tAmentPartyAffairs.setStatus("4"); tAmentPartyAffairs.setNowScore(String.valueOf(reviewScore+before)); return toAjax(partyAffairsService.updateTAmentPartyAffairs(tAmentPartyAffairs)); } /** * 驳回 * @param tAmentPartyAffairs * @return */ @GetMapping("/reback") @ResponseBody public AjaxResult reback(TAmentPartyAffairs tAmentPartyAffairs) { tAmentPartyAffairs.setStatus("3"); return toAjax(partyAffairsService.updateTAmentPartyAffairs(tAmentPartyAffairs)); } /** * 任务预警 */ // @RequiresPermissions("base:affairs:list") @PostMapping("/warnList") @ResponseBody public TableDataInfo warnList(@RequestBody TAmentPartyAffairs tAmentPartyAffairs) { startPage(tAmentPartyAffairs.getPageNum(),tAmentPartyAffairs.getPageSize()); tAmentPartyAffairs.setStatus("1"); List list = partyAffairsService.warnList(tAmentPartyAffairs); return getDataTable(list); } /** * 审批预警 */ // @RequiresPermissions("base:affairs:list") @PostMapping("/approveList") @ResponseBody public TableDataInfo approveList(@RequestBody TAmentPartyAffairs tAmentPartyAffairs) { startPage(tAmentPartyAffairs.getPageNum(),tAmentPartyAffairs.getPageSize()); tAmentPartyAffairs.setStatus("2"); List list = partyAffairsService.approveList(tAmentPartyAffairs); return getDataTable(list); } }