From dc3e176eb03c9104eef6f856f40d2c7b3c78bcc4 Mon Sep 17 00:00:00 2001 From: hshansha Date: Sat, 12 Jul 2025 11:18:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=BB=E8=A1=A8=E7=94=9F=E6=88=90=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kaohe/controller/KhGatherController.java | 215 +++++++++++++----- .../controller/KhKhrwResultController.java | 5 +- .../com/ruoyi/kaohe/domain/KhgatherParam.java | 53 +++++ 3 files changed, 208 insertions(+), 65 deletions(-) create mode 100644 ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhgatherParam.java diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhGatherController.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhGatherController.java index 4453b0d..16b7440 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhGatherController.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhGatherController.java @@ -1,11 +1,17 @@ package com.ruoyi.kaohe.controller; -import java.util.List; +import java.math.BigDecimal; +import java.util.*; import javax.servlet.http.HttpServletResponse; -import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; +import com.ruoyi.kaohe.domain.KhKhrwResult; +import com.ruoyi.kaohe.domain.KhgatherParam; +import com.ruoyi.kaohe.service.IKhKhrwResultService; +import com.ruoyi.kaohe.service.IKhVoteEmpService; +import com.ruoyi.kaohe.service.IKhVoteService; +import com.ruoyi.kaohe.util.PinYinUtil; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -27,72 +33,161 @@ import com.ruoyi.common.core.page.TableDataInfo; /** * 生成汇总Controller - * + * * @author hs * @date 2025-07-10 */ @RestController @RequestMapping("/kaohe/gather") -public class KhGatherController extends BaseController -{ +public class KhGatherController extends BaseController { + @Autowired + private IKhKhrwResultService khKhrwResultService; + @Autowired + private IKhVoteEmpService voteEmpService; + @Autowired + private IKhVoteService khVoteService; @Autowired private IKhGatherService khGatherService; /** - * 查询生成汇总列表 + * 生成汇总列表 */ - @PreAuthorize("@ss.hasPermi('kaohe:gather:list')") + //@PreAuthorize("@ss.hasPermi('kaohe:gather:list')") @PostMapping("/generateSum") - public AjaxResult generateSum(JSONObject json) - { - String hz_name = json.getString("title"); - JSONArray data = json.getJSONArray("data"); + public AjaxResult generateSum(@RequestBody String json) { + // 将String转换为JSONObject + JSONObject jsonObject = JSONObject.parseObject(json); + String hz_name = jsonObject.getString("title"); + JSONArray datas = jsonObject.getJSONArray("data"); + //拼接表头数据 + JSONArray header = new JSONArray();//存放表头及表格关联数据 //---------------------------------------------------------------------------------------------- - for (int i = 0; i < data.size(); i++) { - JSONObject jsonObject = data.getJSONObject(i); - String type1 = jsonObject.getString("type"); - if(type1.equals("0")){ - JSONArray data1 = jsonObject.getJSONArray("data"); - }else{ + //循环主标题下的每一个子节点 + Map nodes = parseJson(datas, hz_name); + JSONObject btKhdx = (JSONObject)nodes.get("btKhdx"); + JSONObject head = (JSONObject) nodes.get("head"); + JSONArray oldchildren = head.getJSONArray("children"); + JSONArray newChildren = new JSONArray(); + newChildren.add(btKhdx); + for (Object oldchild : oldchildren) { + newChildren.add(oldchild); + } + head.put("children",newChildren); + header.add(head); + return AjaxResult.success(header); + } + + //递归解析json + private Map parseJson(JSONArray datas, String titleP) { + Map result = new HashMap<>(); + //父级表头 + JSONObject btKhdx = new JSONObject(); + JSONObject btTitle = new JSONObject(); + btTitle.put("name", PinYinUtil.getPinyinInitials(titleP)); + btTitle.put("label", titleP); + JSONArray btchildren = new JSONArray(); +//--------------------------------------------------------------------- + JSONArray bd = new JSONArray();//表数据拼接 + List alldatas = new ArrayList<>(); + + + for (int i = 0; i < datas.size(); i++) { + JSONObject jobj = (JSONObject) datas.get(i); + String type = jobj.getString("type"); + String title = jobj.getString("title"); + //如果有子集就遍历 + if (type.equals("0")) { + JSONArray data2 = jobj.getJSONArray("data"); + BigDecimal zb = jobj.getBigDecimal("zb"); + Map childmap = parseJson(data2,title); + JSONObject head= (JSONObject)childmap.get("head"); + btchildren.add(head); + + + } else if (type.equals("1")) { //引用占比考核任务 + Long pcId = jobj.getLong("id"); + BigDecimal zb = jobj.getBigDecimal("zb"); + KhKhrwResult khrwResult = new KhKhrwResult(); + khrwResult.setPcId(pcId); + //获取考核任务结果 + List khrw = khKhrwResultService.selectKhKhrwResultList(khrwResult); + if(khrw!=null&&khrw.size()>0){ + JSONArray tableHeader = JSONArray.parse(khrw.get(0).getTableHeader()); + JSONObject head1 = new JSONObject(); + JSONObject head2 = new JSONObject(); + btKhdx=tableHeader.getJSONObject(0);//下标0 单位/姓名 + head1=tableHeader.getJSONObject(1); //整体数据 + head2=tableHeader.getJSONObject(2);//得分 + btchildren.add(head1); + btchildren.add(head2); + } + + //------------------------------------------------------------------------------------------ + JSONArray tabledata = JSONArray.parse(khrw.get(0).getTableData()); + alldatas.addAll(tabledata); + } else { //引用不占比考核任务 + Long pcId = jobj.getLong("id"); + KhKhrwResult khrwResult = new KhKhrwResult(); + khrwResult.setPcId(pcId); + List khrw = khKhrwResultService.selectKhKhrwResultList(khrwResult); + if(khrw!=null&&khrw.size()>0){ + JSONArray tableHeader = JSONArray.parse(khrw.get(0).getTableHeader()); + JSONObject head1 = new JSONObject(); + JSONObject head2 = new JSONObject(); + btKhdx=tableHeader.getJSONObject(0);//下标0 单位/姓名 + head1=tableHeader.getJSONObject(1); //整体数据 + head2=tableHeader.getJSONObject(2);//得分 + btchildren.add(head1); + btchildren.add(head2); + } + + //------------------------------------------------------------------------------------------ + JSONArray tabledata = JSONArray.parse(khrw.get(0).getTableData()); + alldatas.addAll(tabledata); } } + btTitle.put("children",btchildren); + result.put("head", btTitle); + result.put("data", bd); + result.put("btKhdx", btKhdx); + return result; + } /*{ - "hz_name": "教学单位领导班子考核总分", - "data": [{ - "type": 0, - "title": "二级单位目标管理与绩效考核成绩", - "zb": 0.7, - "data": [{ - "type": 1, - "title": "党建与行政目标任务", - "id": 1, - "zb": 0.1 - }, - { - "type": 1, - "title": "事业发展", - "id": 3, - "zb": 0.9 - } - ] - }, - { - "type": 1, - "title": "民主测评", - "id": 2, - "zb": 0.3 - }, - { - "type": 1, - "title": "创新", - "id": 3 - } - ] + "title": "教学单位领导班子考核总分", + "data": [ + { + "type": "0", + "title": "二级单位目标管理与绩效考核成绩", + "data": [ + { + "type": 1, + "title": "党建与行政目标任务", + "id": 1, + "zb": 0.1 + }, + { + "type": "1", + "title": "事业发展", + "id": 4, + "zb": 0.9 + } + ] + }, + { + "type": "1", + "title": "民主测评", + "id": 2, + "zb": 0.3 + }, + { + "type": "1", + "title": "创新", + "id": 5 + } + ] }*/ - return AjaxResult.success(); - } /** @@ -100,8 +195,7 @@ public class KhGatherController extends BaseController */ @PreAuthorize("@ss.hasPermi('kaohe:gather:list')") @GetMapping("/list") - public TableDataInfo list(KhGather khGather) - { + public TableDataInfo list(KhGather khGather) { startPage(); List list = khGatherService.selectKhGatherList(khGather); return getDataTable(list); @@ -113,8 +207,7 @@ public class KhGatherController extends BaseController @PreAuthorize("@ss.hasPermi('kaohe:gather:export')") @Log(title = "生成汇总", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, KhGather khGather) - { + public void export(HttpServletResponse response, KhGather khGather) { List list = khGatherService.selectKhGatherList(khGather); ExcelUtil util = new ExcelUtil(KhGather.class); util.exportExcel(response, list, "生成汇总数据"); @@ -125,8 +218,7 @@ public class KhGatherController extends BaseController */ @PreAuthorize("@ss.hasPermi('kaohe:gather:query')") @GetMapping(value = "/{id}") - public AjaxResult getInfo(@PathVariable("id") Long id) - { + public AjaxResult getInfo(@PathVariable("id") Long id) { return success(khGatherService.selectKhGatherById(id)); } @@ -136,8 +228,7 @@ public class KhGatherController extends BaseController @PreAuthorize("@ss.hasPermi('kaohe:gather:add')") @Log(title = "生成汇总", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody KhGather khGather) - { + public AjaxResult add(@RequestBody KhGather khGather) { return toAjax(khGatherService.insertKhGather(khGather)); } @@ -147,8 +238,7 @@ public class KhGatherController extends BaseController @PreAuthorize("@ss.hasPermi('kaohe:gather:edit')") @Log(title = "生成汇总", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody KhGather khGather) - { + public AjaxResult edit(@RequestBody KhGather khGather) { return toAjax(khGatherService.updateKhGather(khGather)); } @@ -157,9 +247,8 @@ public class KhGatherController extends BaseController */ @PreAuthorize("@ss.hasPermi('kaohe:gather:remove')") @Log(title = "生成汇总", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") - public AjaxResult remove(@PathVariable Long[] ids) - { + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(khGatherService.deleteKhGatherByIds(ids)); } } diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhKhrwResultController.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhKhrwResultController.java index 2ec83db..7c0f908 100644 --- a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhKhrwResultController.java +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/controller/KhKhrwResultController.java @@ -175,17 +175,18 @@ public class KhKhrwResultController extends BaseController { children2.add(tabledata2); } } else {//单独评分 + sumScore = sumScore.add(voteEmp.getAvgScore()); + votesDatas.put("khx"+index2, voteEmp.getAvgScore()); if (index1 == 1) { - votesDatas.put("khx"+index2, voteEmp.getAvgScore()); children2.add(tabledata); } - sumScore = sumScore.add(voteEmp.getAvgScore()); } } pcdata.put("khdx", key); pcdata.put(pyPCtitle, votesDatas); pcdata.put("df", sumScore); endData.add(pcdata); + if (index1 == 1) { tableColumn2.put("children", children2); } diff --git a/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhgatherParam.java b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhgatherParam.java new file mode 100644 index 0000000..05bddf5 --- /dev/null +++ b/ruoyi-kaohe/src/main/java/com/ruoyi/kaohe/domain/KhgatherParam.java @@ -0,0 +1,53 @@ +package com.ruoyi.kaohe.domain; + +import java.math.BigDecimal; +import java.util.List; + +public class KhgatherParam { + private String title; + private String type; + private BigDecimal zb; + private Long id; + + private List data; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public BigDecimal getZb() { + return zb; + } + + public void setZb(BigDecimal zb) { + this.zb = zb; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } +}