From 7813b864a66bd7a0f5b9aaa4cc63d67728423bf4 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期二, 23 四月 2024 10:52:11 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java | 155 +++------ ycl-server/src/main/resources/mapper/zgyw/TContractMapper.xml | 83 ----- ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java | 163 +++++---- ycl-server/src/main/java/com/ycl/handler/CommentWriteHandler.java | 37 ++ ycl-server/src/main/java/com/ycl/platform/mapper/TContractMapper.java | 54 --- ycl-server/src/main/java/com/ycl/platform/service/ITContractService.java | 56 --- ycl-server/src/main/java/com/ycl/platform/controller/TContractController.java | 82 ++-- pom.xml | 6 ycl-pojo/src/main/java/com/ycl/platform/domain/entity/TContract.java | 153 ++------- ycl-server/src/main/java/com/ycl/handler/CustomSheetWriteHandler.java | 84 +++++ 10 files changed, 360 insertions(+), 513 deletions(-) diff --git a/pom.xml b/pom.xml index c345219..2598e4c 100644 --- a/pom.xml +++ b/pom.xml @@ -246,6 +246,12 @@ <artifactId>jaxb-api</artifactId> <version>${jaxb-api.version}</version> </dependency> + + <dependency> + <groupId>com.alibaba</groupId> + <artifactId>easyexcel</artifactId> + <version>${easyexcel.version}</version> + </dependency> </dependencies> <build> diff --git a/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java index 3439154..c554b6c 100644 --- a/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java +++ b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/CalculateRule.java @@ -1,9 +1,13 @@ package com.ycl.platform.domain.entity; -import annotation.Excel; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ContentStyle; +import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum; +import com.alibaba.excel.enums.poi.VerticalAlignmentEnum; +import com.baomidou.mybatisplus.annotation.TableLogic; import com.ycl.system.domain.TreeEntity; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; +import lombok.Data; /** * 鍒嗘暟鏍哥畻瑙勫垯瀵硅薄 t_default_rule @@ -11,112 +15,65 @@ * @author ruoyi * @date 2024-04-01 */ -public class CalculateRule extends TreeEntity -{ +@Data +@ExcelIgnoreUnannotated +@ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER) +public class CalculateRule extends TreeEntity { private static final long serialVersionUID = 1L; - /** 涓婚敭 */ + /** + * 涓婚敭 + */ + @ExcelProperty("搴忓彿") private Long id; - /** 瑙勫垯鍚嶇О */ - @Excel(name = "瑙勫垯鍚嶇О") + /** + * 鍗曚綅id + */ + private Integer unitId; + + /** + * 瑙勫垯鍚嶇О + */ + @ExcelProperty("鑰冩牳鍐呭") private String ruleName; - /** 鎵e噺鏂瑰紡 */ - @Excel(name = "鎵e噺鏂瑰紡") - private Long deductCategory; + /** + * 鍏宠仈涓婄骇id + */ + private Long parentId; - /** 浜哄伐鎵撳垎/绯荤粺鎵撳垎 */ - private Long deductWay; - - /** 瑙勫垯鎻忚堪 */ - @Excel(name = "瑙勫垯鎻忚堪") + /** + * 瑙勫垯鎻忚堪 + */ + @ExcelProperty("璇勫垽鏍囧噯") private String ruleDesc; - /** 瑙勫垯鐘舵�� */ - @Excel(name = "瑙勫垯鐘舵��") - private String ruleStatus; + /** + * 瑙勫垯鏉′欢 + */ + @ExcelProperty("鑰冩牳瑕佹眰") + private String ruleCondition; - /** 閫昏緫鍒犻櫎 */ + /** + * 鎵e噺鏂瑰紡 1/2/3 鎵f寚瀹氬垎鏁�/鍒嗘暟涔樹互鏁伴噺/闄や互鏁伴噺鍚庝箻浠ュ垎鏁� + */ + @ExcelProperty("鎵e垎鏂瑰紡") + private String deductCategory; + + /** + * 鎵i櫎鍒嗘暟 + */ + @ExcelProperty("鎵e垎鏁板��") + private Double calcFraction; + + /** + * 褰撴柟寮忎负闄や互鏃讹紝闄や互褰撳墠瀛楁鏁伴噺 + */ + @ExcelProperty("闄や互鏁伴噺") + private Integer calcUnit; + + @TableLogic private String deleted; - public void setId(Long id) - { - this.id = id; - } - - public Long getId() - { - return id; - } - public void setRuleName(String ruleName) - { - this.ruleName = ruleName; - } - - public String getRuleName() - { - return ruleName; - } - public void setDeductCategory(Long deductCategory) - { - this.deductCategory = deductCategory; - } - - public Long getDeductCategory() - { - return deductCategory; - } - public void setDeductWay(Long deductWay) - { - this.deductWay = deductWay; - } - - public Long getDeductWay() - { - return deductWay; - } - public void setRuleDesc(String ruleDesc) - { - this.ruleDesc = ruleDesc; - } - - public String getRuleDesc() - { - return ruleDesc; - } - public void setRuleStatus(String ruleStatus) - { - this.ruleStatus = ruleStatus; - } - - public String getRuleStatus() - { - return ruleStatus; - } - public void setDeleted(String deleted) - { - this.deleted = deleted; - } - - public String getDeleted() - { - return deleted; - } - - @Override - public String toString() { - return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) - .append("id", getId()) - .append("ruleName", getRuleName()) - .append("parentId", getParentId()) - .append("deductCategory", getDeductCategory()) - .append("deductWay", getDeductWay()) - .append("ruleDesc", getRuleDesc()) - .append("ruleStatus", getRuleStatus()) - .append("createTime", getCreateTime()) - .append("updateTime", getUpdateTime()) - .append("deleted", getDeleted()) - .toString(); - } } diff --git a/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/TContract.java b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/TContract.java index 5c7e9ad..8cdb71e 100644 --- a/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/TContract.java +++ b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/TContract.java @@ -1,135 +1,58 @@ package com.ycl.platform.domain.entity; -import annotation.Excel; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ContentStyle; +import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum; +import com.alibaba.excel.enums.poi.VerticalAlignmentEnum; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.fasterxml.jackson.annotation.JsonFormat; import com.ycl.system.entity.BaseEntity; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; +import lombok.Data; import java.util.Date; /** - * 銆愯濉啓鍔熻兘鍚嶇О銆戝璞� t_contract - * - * @author ruoyi - * @date 2024-03-12 + * 杩愮淮鍚堝悓瀵硅薄 t_contract + * + * @author gonghl + * @date 2024-04-22 */ -public class TContract extends BaseEntity -{ +@Data +@ExcelIgnoreUnannotated +@ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, verticalAlignment = VerticalAlignmentEnum.CENTER) +public class TContract extends BaseEntity { private static final long serialVersionUID = 1L; - /** 涓婚敭 */ + /** + * 涓婚敭 + */ + @ExcelProperty("搴忓彿") private Long id; - /** 鍏徃id */ - @Excel(name = "鍏徃id") - private Long companyId; + /** + * 鍗曚綅id + */ + private Integer unitId; - /** 鍏徃鍚� */ - @Excel(name = "鍏徃鍚�") - private String companyName; + /** + * 鍚堝悓鍚嶇О + */ + private String name; - /** 瀵规帴鍏畨閮ㄩ棬id */ - @Excel(name = "瀵规帴鍏畨閮ㄩ棬id") - private Long deptId; - - /** 閮ㄩ棬鍚嶇О */ - @Excel(name = "閮ㄩ棬鍚嶇О") - private String deptName; - - /** 鍚堝悓鏄庣粏json */ - @Excel(name = "鍚堝悓鏄庣粏json") - private String detail; - - /** 寮�濮嬫椂闂� */ - @Excel(name = "寮�濮嬫椂闂�") + /** + * 寮�濮嬫椂闂� + */ + @JsonFormat(pattern = "yyyy-MM-dd") private Date startTime; - /** 鎴鏃堕棿 */ - @Excel(name = "鎴鏃堕棿") + /** + * 缁撴潫鏃堕棿 + */ + @JsonFormat(pattern = "yyyy-MM-dd") private Date endTime; - public Date getStartTime() { - return startTime; - } + @TableLogic + private String deleted; - public void setStartTime(Date startTime) { - this.startTime = startTime; - } - - public Date getEndTime() { - return endTime; - } - - public void setEndTime(Date endTime) { - this.endTime = endTime; - } - - public void setId(Long id) - { - this.id = id; - } - - public Long getId() - { - return id; - } - public void setCompanyId(Long companyId) - { - this.companyId = companyId; - } - - public Long getCompanyId() - { - return companyId; - } - public void setCompanyName(String companyName) - { - this.companyName = companyName; - } - - public String getCompanyName() - { - return companyName; - } - public void setDeptId(Long deptId) - { - this.deptId = deptId; - } - - public Long getDeptId() - { - return deptId; - } - public void setDeptName(String deptName) - { - this.deptName = deptName; - } - - public String getDeptName() - { - return deptName; - } - public void setDetail(String detail) - { - this.detail = detail; - } - - public String getDetail() - { - return detail; - } - - @Override - public String toString() { - return "TContract{" + - "id=" + id + - ", companyId=" + companyId + - ", companyName='" + companyName + '\'' + - ", deptId=" + deptId + - ", deptName='" + deptName + '\'' + - ", detail='" + detail + '\'' + - ", startTime=" + startTime + - ", endTime=" + endTime + - '}'; - } } diff --git a/ycl-server/src/main/java/com/ycl/handler/CommentWriteHandler.java b/ycl-server/src/main/java/com/ycl/handler/CommentWriteHandler.java new file mode 100644 index 0000000..dff2657 --- /dev/null +++ b/ycl-server/src/main/java/com/ycl/handler/CommentWriteHandler.java @@ -0,0 +1,37 @@ +package com.ycl.handler; + +import com.alibaba.excel.util.BooleanUtils; +import com.alibaba.excel.write.handler.RowWriteHandler; +import com.alibaba.excel.write.handler.context.RowWriteHandlerContext; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.Comment; +import org.apache.poi.ss.usermodel.Drawing; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.xssf.usermodel.XSSFClientAnchor; +import org.apache.poi.xssf.usermodel.XSSFRichTextString; + +/** + * 鑷畾涔夋嫤鎴櫒.鏂板娉ㄩ噴,绗竴琛屽ご鍔犳壒娉� + * + * @author gonghl + */ +@Slf4j +public class CommentWriteHandler implements RowWriteHandler { + + @Override + public void afterRowDispose(RowWriteHandlerContext context) { + if (BooleanUtils.isTrue(context.getHead())) { + Sheet sheet = context.getWriteSheetHolder().getSheet(); + Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch(); + + Comment comment1 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, 5, 4, 4, 5)); + comment1.setString(new XSSFRichTextString("鎵i櫎鐩稿叧闀滃ご鏁伴噺*0.1鍒�")); + sheet.getRow(0).getCell(1).setCellComment(comment1); + + Comment comment2 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, 5, 7, 7, 8)); + comment2.setString(new XSSFRichTextString("鎵�2鍒�/12灏忔椂")); + sheet.getRow(0).getCell(1).setCellComment(comment2); + } + } + +} diff --git a/ycl-server/src/main/java/com/ycl/handler/CustomSheetWriteHandler.java b/ycl-server/src/main/java/com/ycl/handler/CustomSheetWriteHandler.java new file mode 100644 index 0000000..10ed275 --- /dev/null +++ b/ycl-server/src/main/java/com/ycl/handler/CustomSheetWriteHandler.java @@ -0,0 +1,84 @@ +package com.ycl.handler; + +import com.alibaba.excel.write.handler.SheetWriteHandler; +import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; +import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 鍚堝悓妯℃澘涓嬫媺妗� + * @author gonghl + */ +public class CustomSheetWriteHandler implements SheetWriteHandler { + + private List<String> selectDataList; + + public CustomSheetWriteHandler(List<String> selectDataList) { + this.selectDataList = selectDataList; + } + + /** + * 鎯冲疄鐜癊xcel寮曠敤鍏朵粬sheet椤垫暟鎹綔涓哄崟鍏冩牸涓嬫媺閫夐」鍊硷紝 + * 闇�瑕侀噸鍐欒鏂规硶 + * + * @param writeWorkbookHolder + * @param writeSheetHolder + */ + @Override + public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) { + + // 鏋勯�犱笅鎷夐�夐」鍗曞厓鏍煎垪鐨勪綅缃紝浠ュ強涓嬫媺閫夐」鍙�夊弬鏁板�肩殑map闆嗗悎 + // key锛氫笅鎷夐�夐」瑕佹斁鍒板摢涓崟鍏冩牸锛屾瘮濡侫鍒楃殑鍗曞厓鏍奸偅灏辨槸0锛孋鍒楃殑鍗曞厓鏍硷紝閭e氨鏄�2 + // value锛歬ey瀵瑰簲鐨勯偅涓崟鍏冩牸涓嬫媺鍒楄〃閲岀殑鏁版嵁椤癸紝姣斿杩欓噷灏辨槸涓嬫媺閫夐」1..100 + Map<Integer, List<String>> selectParamMap = new HashMap<>(); + selectParamMap.put(4, selectDataList); + + // 鑾峰彇绗竴涓猻heet椤� + Sheet sheet = writeSheetHolder.getCachedSheet(); + // 鑾峰彇sheet椤电殑鏁版嵁鏍¢獙瀵硅薄 + DataValidationHelper helper = sheet.getDataValidationHelper(); + // 鑾峰彇宸ヤ綔绨垮璞★紝鐢ㄤ簬鍒涘缓瀛樻斁涓嬫媺鏁版嵁鐨勫瓧鍏竤heet鏁版嵁椤� + Workbook workbook = writeWorkbookHolder.getWorkbook(); + + // 杩唬绱㈠紩锛岀敤浜庡瓨鏀句笅鎷夋暟鎹殑瀛楀吀sheet鏁版嵁椤靛懡鍚� + int index = 1; + for (Map.Entry<Integer, List<String>> entry : selectParamMap.entrySet()) { + + // 璁剧疆瀛樻斁涓嬫媺鏁版嵁鐨勫瓧鍏竤heet锛屽苟鎶婅繖浜泂heet闅愯棌鎺夛紝杩欐牱鐢ㄦ埛浜や簰鏇村弸濂� + String dictSheetName = "dict_hide_sheet" + index; + Sheet dictSheet = workbook.createSheet(dictSheetName); + // 闅愯棌瀛楀吀sheet椤� + workbook.setSheetHidden(index++, true); + + // 璁剧疆涓嬫媺鍒楄〃瑕嗙洊鐨勮鏁帮紝浠庣涓�琛屽紑濮嬪埌鏈�鍚庝竴琛岋紝杩欓噷娉ㄦ剰锛孍xcel琛岀殑 + // 绱㈠紩鏄粠0寮�濮嬬殑锛屾垜杩欒竟绗�0琛屾槸鏍囬琛岋紝绗�1琛屽紑濮嬫椂鏁版嵁鍖栵紝鍙牴鎹疄 + // 闄呬笟鍔¤缃湡姝g殑鏁版嵁寮�濮嬭锛屽鏋滆璁剧疆鍒版渶鍚庝竴琛岋紝閭d箞涓�瀹氭敞鎰忥紝 + // 鏈�鍚庝竴琛岀殑琛岀储寮曟槸1048575锛屽崈涓囧埆鍐欐垚1048576锛屼笉鐒朵細瀵艰嚧涓嬫媺鍒楄〃 + // 澶辨晥锛屽嚭涓嶆潵 + CellRangeAddressList infoList = new CellRangeAddressList(1, 1048575, entry.getKey(), entry.getKey()); + int rowLen = entry.getValue().size(); + for (int i = 0; i < rowLen; i++) { + // 鍚戝瓧鍏竤heet鍐欐暟鎹紝浠庣涓�琛屽紑濮嬪啓锛屾澶勫彲鏍规嵁鑷繁涓氬姟闇�瑕侊紝鑷畾 + // 涔変粠绗嚑琛岃繕鏄啓锛屽啓鐨勬椂鍊欐敞鎰忎竴涓嬭绱㈠紩鏄粠0寮�濮嬬殑鍗冲彲 + dictSheet.createRow(i).createCell(0).setCellValue(entry.getValue().get(i)); + } + + // 璁剧疆鍏宠仈鏁版嵁鍏紡锛岃繖涓牸寮忚窡Excel璁剧疆鏈夋晥鎬ф暟鎹殑琛ㄨ揪寮忔槸涓�鏍风殑 + String refers = dictSheetName + "!$A$1:$A$" + entry.getValue().size(); + Name name = workbook.createName(); + name.setNameName(dictSheetName); + // 灏嗗叧鑱斿叕寮忓拰sheet椤靛仛鍏宠仈 + name.setRefersToFormula(refers); + + // 灏嗕笂闈㈣缃ソ鐨勪笅鎷夊垪琛ㄥ瓧鍏竤heet椤靛拰鐩爣sheet鍏宠仈璧锋潵 + DataValidationConstraint constraint = helper.createFormulaListConstraint(dictSheetName); + DataValidation dataValidation = helper.createValidation(constraint, infoList); + sheet.addValidationData(dataValidation); + } + } +} \ No newline at end of file diff --git a/ycl-server/src/main/java/com/ycl/platform/controller/TContractController.java b/ycl-server/src/main/java/com/ycl/platform/controller/TContractController.java index 3ec4f1c..0d463e2 100644 --- a/ycl-server/src/main/java/com/ycl/platform/controller/TContractController.java +++ b/ycl-server/src/main/java/com/ycl/platform/controller/TContractController.java @@ -5,16 +5,13 @@ import com.ycl.platform.service.ITContractService; import com.ycl.system.AjaxResult; import com.ycl.system.controller.BaseController; -import com.ycl.system.page.TableDataInfo; import com.ycl.utils.poi.ExcelUtil; import enumeration.BusinessType; import jakarta.servlet.http.HttpServletResponse; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.AllArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; - - -import java.util.List; +import org.springframework.web.multipart.MultipartFile; /** * 銆愯濉啓鍔熻兘鍚嶇О銆慍ontroller @@ -24,76 +21,75 @@ */ @RestController @RequestMapping("/system/contract") -public class TContractController extends BaseController -{ - @Autowired - private ITContractService tContractService; +@AllArgsConstructor +public class TContractController extends BaseController { + + private final ITContractService tContractService; + /** - * 鏌ヨ銆愯濉啓鍔熻兘鍚嶇О銆戝垪琛� + * 鍚堝悓瀵煎叆妯℃澘 */ - @PreAuthorize("@ss.hasPermi('system:contract:list')") - @GetMapping("/list") - public TableDataInfo list(TContract tContract) - { - startPage(); - List<TContract> list = tContractService.selectTContractList(tContract); - return getDataTable(list); + @PreAuthorize("@ss.hasPermi('system:contract:importTemplate')") + @Log(title = "瀵煎叆妯℃澘", businessType = BusinessType.IMPORT) + @PostMapping("/importTemplate") + public void importTemplate(HttpServletResponse response) { + tContractService.importTemplate(response); } /** - * 瀵煎嚭銆愯濉啓鍔熻兘鍚嶇О銆戝垪琛� + * 鍚堝悓瀵煎叆 + * + * @param file 瀵煎叆鏂囦欢 + * @param unitId 杩愮淮鍗曚綅 + * @param startTime 寮�濮嬫椂闂� + * @param endTime 缁撴潫鏃堕棿 + * @return 瀵煎叆缁撴灉 */ - @PreAuthorize("@ss.hasPermi('system:contract:export')") - @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�", businessType = BusinessType.EXPORT) - @PostMapping("/export") - public void export(HttpServletResponse response, TContract tContract) - { - List<TContract> list = tContractService.selectTContractList(tContract); - ExcelUtil<TContract> util = new ExcelUtil<TContract>(TContract.class); - util.exportExcel(response, list, "銆愯濉啓鍔熻兘鍚嶇О銆戞暟鎹�"); + @Log(title = "鍚堝悓瀵煎叆", businessType = BusinessType.IMPORT) + @PreAuthorize("@ss.hasPermi('system:user:import')") + @PostMapping("/importData") + public AjaxResult importData(MultipartFile file, String unitId, String startTime, String endTime) { + ExcelUtil<TContract> util = new ExcelUtil<>(TContract.class); + return success(); } /** * 鑾峰彇銆愯濉啓鍔熻兘鍚嶇О銆戣缁嗕俊鎭� */ - @PreAuthorize("@ss.hasPermi('system:contract:query')") + @PreAuthorize("@ss.hasPermi('system:contract:query')") @GetMapping(value = "/{id}") - public AjaxResult getInfo(@PathVariable("id") Long id) - { - return success(tContractService.selectTContractById(id)); + public AjaxResult getInfo(@PathVariable("id") Long id) { + return success(tContractService.getById(id)); } /** * 鏂板銆愯濉啓鍔熻兘鍚嶇О銆� */ - @PreAuthorize("@ss.hasPermi('system:contract:add')") + @PreAuthorize("@ss.hasPermi('system:contract:add')") @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody TContract tContract) - { - return toAjax(tContractService.insertTContract(tContract)); + public AjaxResult add(@RequestBody TContract tContract) { + return toAjax(tContractService.save(tContract)); } /** * 淇敼銆愯濉啓鍔熻兘鍚嶇О銆� */ - @PreAuthorize("@ss.hasPermi('system:contract:edit')") + @PreAuthorize("@ss.hasPermi('system:contract:edit')") @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody TContract tContract) - { - return toAjax(tContractService.updateTContract(tContract)); + public AjaxResult edit(@RequestBody TContract tContract) { + return toAjax(tContractService.updateById(tContract)); } /** * 鍒犻櫎銆愯濉啓鍔熻兘鍚嶇О銆� */ - @PreAuthorize("@ss.hasPermi('system:contract:remove')") + @PreAuthorize("@ss.hasPermi('system:contract:remove')") @Log(title = "銆愯濉啓鍔熻兘鍚嶇О銆�", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") - public AjaxResult remove(@PathVariable Long[] ids) - { - return toAjax(tContractService.deleteTContractByIds(ids)); + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(tContractService.removeById(ids)); } } diff --git a/ycl-server/src/main/java/com/ycl/platform/mapper/TContractMapper.java b/ycl-server/src/main/java/com/ycl/platform/mapper/TContractMapper.java index d7b483e..fb4a704 100644 --- a/ycl-server/src/main/java/com/ycl/platform/mapper/TContractMapper.java +++ b/ycl-server/src/main/java/com/ycl/platform/mapper/TContractMapper.java @@ -3,61 +3,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ycl.platform.domain.entity.TContract; -import java.util.List; - /** * 銆愯濉啓鍔熻兘鍚嶇О銆慚apper鎺ュ彛 - * + * * @author ruoyi * @date 2024-03-12 */ -public interface TContractMapper extends BaseMapper<TContract> -{ - /** - * 鏌ヨ銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param id 銆愯濉啓鍔熻兘鍚嶇О銆戜富閿� - * @return 銆愯濉啓鍔熻兘鍚嶇О銆� - */ - public TContract selectTContractById(Long id); - - /** - * 鏌ヨ銆愯濉啓鍔熻兘鍚嶇О銆戝垪琛� - * - * @param tContract 銆愯濉啓鍔熻兘鍚嶇О銆� - * @return 銆愯濉啓鍔熻兘鍚嶇О銆戦泦鍚� - */ - public List<TContract> selectTContractList(TContract tContract); - - /** - * 鏂板銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param tContract 銆愯濉啓鍔熻兘鍚嶇О銆� - * @return 缁撴灉 - */ - public int insertTContract(TContract tContract); - - /** - * 淇敼銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param tContract 銆愯濉啓鍔熻兘鍚嶇О銆� - * @return 缁撴灉 - */ - public int updateTContract(TContract tContract); - - /** - * 鍒犻櫎銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param id 銆愯濉啓鍔熻兘鍚嶇О銆戜富閿� - * @return 缁撴灉 - */ - public int deleteTContractById(Long id); - - /** - * 鎵归噺鍒犻櫎銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param ids 闇�瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎 - * @return 缁撴灉 - */ - public int deleteTContractByIds(Long[] ids); +public interface TContractMapper extends BaseMapper<TContract> { } diff --git a/ycl-server/src/main/java/com/ycl/platform/service/ITContractService.java b/ycl-server/src/main/java/com/ycl/platform/service/ITContractService.java index dae7f78..ba9cac0 100644 --- a/ycl-server/src/main/java/com/ycl/platform/service/ITContractService.java +++ b/ycl-server/src/main/java/com/ycl/platform/service/ITContractService.java @@ -1,62 +1,20 @@ package com.ycl.platform.service; +import com.baomidou.mybatisplus.extension.service.IService; import com.ycl.platform.domain.entity.TContract; - -import java.util.List; +import jakarta.servlet.http.HttpServletResponse; /** * 銆愯濉啓鍔熻兘鍚嶇О銆慡ervice鎺ュ彛 - * + * * @author ruoyi * @date 2024-03-12 */ -public interface ITContractService -{ - /** - * 鏌ヨ銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param id 銆愯濉啓鍔熻兘鍚嶇О銆戜富閿� - * @return 銆愯濉啓鍔熻兘鍚嶇О銆� - */ - public TContract selectTContractById(Long id); +public interface ITContractService extends IService<TContract> { /** - * 鏌ヨ銆愯濉啓鍔熻兘鍚嶇О銆戝垪琛� - * - * @param tContract 銆愯濉啓鍔熻兘鍚嶇О銆� - * @return 銆愯濉啓鍔熻兘鍚嶇О銆戦泦鍚� + * 瀵煎叆鍚堝悓妯℃澘 + * @param response 缁撴灉 */ - public List<TContract> selectTContractList(TContract tContract); - - /** - * 鏂板銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param tContract 銆愯濉啓鍔熻兘鍚嶇О銆� - * @return 缁撴灉 - */ - public int insertTContract(TContract tContract); - - /** - * 淇敼銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param tContract 銆愯濉啓鍔熻兘鍚嶇О銆� - * @return 缁撴灉 - */ - public int updateTContract(TContract tContract); - - /** - * 鎵归噺鍒犻櫎銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param ids 闇�瑕佸垹闄ょ殑銆愯濉啓鍔熻兘鍚嶇О銆戜富閿泦鍚� - * @return 缁撴灉 - */ - public int deleteTContractByIds(Long[] ids); - - /** - * 鍒犻櫎銆愯濉啓鍔熻兘鍚嶇О銆戜俊鎭� - * - * @param id 銆愯濉啓鍔熻兘鍚嶇О銆戜富閿� - * @return 缁撴灉 - */ - public int deleteTContractById(Long id); + void importTemplate(HttpServletResponse response); } diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java index f3296a3..988d72f 100644 --- a/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java +++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/TContractServiceImpl.java @@ -1,95 +1,110 @@ package com.ycl.platform.service.impl; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.write.merge.LoopMergeStrategy; +import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ycl.handler.CommentWriteHandler; +import com.ycl.handler.CustomSheetWriteHandler; +import com.ycl.platform.domain.entity.CalculateRule; import com.ycl.platform.domain.entity.TContract; import com.ycl.platform.mapper.TContractMapper; import com.ycl.platform.service.ITContractService; -import org.springframework.beans.factory.annotation.Autowired; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.stereotype.Service; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.List; /** * 銆愯濉啓鍔熻兘鍚嶇О銆慡ervice涓氬姟灞傚鐞� - * + * * @author ruoyi * @date 2024-03-12 */ @Service -public class TContractServiceImpl extends ServiceImpl<TContractMapper, TContract> implements ITContractService -{ - @Autowired - private TContractMapper tContractMapper; - - /** - * 鏌ヨ銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param id 銆愯濉啓鍔熻兘鍚嶇О銆戜富閿� - * @return 銆愯濉啓鍔熻兘鍚嶇О銆� - */ +public class TContractServiceImpl extends ServiceImpl<TContractMapper, TContract> implements ITContractService { @Override - public TContract selectTContractById(Long id) - { - return tContractMapper.selectTContractById(id); + public void importTemplate(HttpServletResponse response) { + try { + List<CalculateRule> list = getExcelData(); + ArrayList<String> arrayList = new ArrayList<>(); + arrayList.add("鎵f寚瀹氬垎鏁�"); + arrayList.add("鍒嗘暟涔樹互鏁伴噺"); + arrayList.add("闄や互鏁伴噺鍚庝箻浠ュ垎鏁�"); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String fileName = URLEncoder.encode("瀵煎叆鍚堝悓妯℃澘", StandardCharsets.UTF_8).replace("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + // 绗竴鍒椼�佺浜屽垪涓婁笅鍚堝苟3琛� + LoopMergeStrategy loopMergeStrategy1 = new LoopMergeStrategy(3, 0); + LoopMergeStrategy loopMergeStrategy2 = new LoopMergeStrategy(3, 1); + EasyExcel.write(response.getOutputStream(), CalculateRule.class) + .registerWriteHandler(loopMergeStrategy1) + .registerWriteHandler(loopMergeStrategy2) + // 鑷�傚簲鍒楀 + .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) + // 涓嬫媺妗� + .registerWriteHandler(new CustomSheetWriteHandler(arrayList)) + // 鏍囨敞 + .registerWriteHandler(new CommentWriteHandler()) + .sheet("鍚堝悓瀵煎叆妯℃澘").doWrite(list); + } catch (Exception e) { + throw new RuntimeException(e); + } } - /** - * 鏌ヨ銆愯濉啓鍔熻兘鍚嶇О銆戝垪琛� - * - * @param tContract 銆愯濉啓鍔熻兘鍚嶇О銆� - * @return 銆愯濉啓鍔熻兘鍚嶇О銆� - */ - @Override - public List<TContract> selectTContractList(TContract tContract) - { - return tContractMapper.selectTContractList(tContract); - } - - /** - * 鏂板銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param tContract 銆愯濉啓鍔熻兘鍚嶇О銆� - * @return 缁撴灉 - */ - @Override - public int insertTContract(TContract tContract) - { - return tContractMapper.insertTContract(tContract); - } - - /** - * 淇敼銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param tContract 銆愯濉啓鍔熻兘鍚嶇О銆� - * @return 缁撴灉 - */ - @Override - public int updateTContract(TContract tContract) - { - return tContractMapper.updateTContract(tContract); - } - - /** - * 鎵归噺鍒犻櫎銆愯濉啓鍔熻兘鍚嶇О銆� - * - * @param ids 闇�瑕佸垹闄ょ殑銆愯濉啓鍔熻兘鍚嶇О銆戜富閿� - * @return 缁撴灉 - */ - @Override - public int deleteTContractByIds(Long[] ids) - { - return tContractMapper.deleteTContractByIds(ids); - } - - /** - * 鍒犻櫎銆愯濉啓鍔熻兘鍚嶇О銆戜俊鎭� - * - * @param id 銆愯濉啓鍔熻兘鍚嶇О銆戜富閿� - * @return 缁撴灉 - */ - @Override - public int deleteTContractById(Long id) - { - return tContractMapper.deleteTContractById(id); + private List<CalculateRule> getExcelData() { + ArrayList<CalculateRule> list = new ArrayList<>(); + CalculateRule calculateRule1 = new CalculateRule(); + calculateRule1.setId(1L); + calculateRule1.setRuleName("瑙嗛骞冲潎鍦ㄧ嚎鐜�"); + calculateRule1.setRuleDesc("锛�1锛夎棰戝湪绾跨巼=瑙嗛鍦ㄧ嚎鏁伴噺梅鍓嶇鏈嶅姟閰嶇疆鏁帮紙搴旀墸闄や笉鍙姉鍔涙垨涓庝腑鏍囦汉鏈嶅姟鏃犲叧閫犳垚鐨勬帀绾块櫎澶栥�傦級"); + calculateRule1.setRuleCondition("鈮�98%"); + calculateRule1.setDeductCategory("鎵f寚瀹氬垎鏁�"); + calculateRule1.setCalcFraction(0.00); + list.add(calculateRule1); + CalculateRule calculateRule2 = new CalculateRule(); + calculateRule2.setRuleDesc("锛�2锛夎棰戝钩鍧囧湪绾跨巼锛氬綋鏈堟瘡鏃ヨ棰戝湪绾跨巼鐨勫钩鍧囧�笺��"); + calculateRule2.setRuleCondition("95%鈮よ棰戝钩鍧囧湪绾跨巼锛�98%"); + calculateRule2.setDeductCategory("鎵f寚瀹氬垎鏁�"); + calculateRule2.setCalcFraction(5.00); + list.add(calculateRule2); + CalculateRule calculateRule3 = new CalculateRule(); + calculateRule3.setRuleDesc("锛�3锛夎棰戝湪绾跨巼淇濈暀鏁存暟骞朵笖鍚戜笅鍙栨暣銆�"); + calculateRule3.setRuleCondition("90%鈮よ棰戝钩鍧囧湪绾跨巼锛�95%"); + calculateRule3.setDeductCategory("鎵f寚瀹氬垎鏁�"); + calculateRule3.setCalcFraction(10.00); + list.add(calculateRule3); + CalculateRule calculateRule4 = new CalculateRule(); + calculateRule4.setId(2L); + calculateRule4.setRuleName("鍓嶇鎰熺煡婧愭不鐞嗗伐浣�"); + calculateRule4.setRuleDesc("鏃堕挓鍚屾锛堣秴杩嚶�3绉掍负涓嶅悎鏍硷級"); + calculateRule4.setRuleCondition("瑙嗛鐩戞帶鎽勫儚鏈烘椂閽熶笉鍚屾锛�24灏忔椂鍐呮湭淇鐨�"); + calculateRule4.setDeductCategory("鍒嗘暟涔樹互鏁伴噺"); + calculateRule4.setCalcFraction(0.1); + list.add(calculateRule4); + CalculateRule calculateRule7 = new CalculateRule(); + calculateRule7.setRuleName("鈥︹�︹�︹��"); + calculateRule7.setRuleDesc("鈥︹�︹�︹��"); + calculateRule7.setRuleCondition("鈥︹�︹�︹��"); + list.add(calculateRule7); + CalculateRule calculateRule6 = new CalculateRule(); + calculateRule6.setRuleName("鈥︹�︹�︹��"); + calculateRule6.setRuleDesc("鈥︹�︹�︹��"); + calculateRule6.setRuleCondition("鈥︹�︹�︹��"); + list.add(calculateRule6); + CalculateRule calculateRule5 = new CalculateRule(); + calculateRule5.setId(3L); + calculateRule5.setRuleName("鍚庡彴绯荤粺鐨勪繚闅�"); + calculateRule5.setRuleDesc("鍦ㄤ釜鍒澶囨晠闅滀絾涓嶅奖鍝嶈鍔熻兘妯″潡鏁翠綋搴旂敤鎯呭喌涓嬶紝椤诲湪72灏忔椂浠ュ唴鎺掗櫎鏁呴殰銆�"); + calculateRule5.setRuleCondition("鍗曟鏁呴殰鏃堕暱鑻ヨ秴鍑�144灏忔椂浠ュ悗锛屾瘡瓒呭嚭12灏忔椂锛堜笉瓒�12灏忔椂鎸�12灏忔椂璁★級"); + calculateRule5.setDeductCategory("闄や互鏁伴噺鍚庝箻浠ュ垎鏁�"); + calculateRule5.setCalcFraction(2.00); + calculateRule5.setCalcUnit(12); + list.add(calculateRule5); + return list; } } diff --git a/ycl-server/src/main/resources/mapper/zgyw/TContractMapper.xml b/ycl-server/src/main/resources/mapper/zgyw/TContractMapper.xml index 712d66b..18a9ccb 100644 --- a/ycl-server/src/main/resources/mapper/zgyw/TContractMapper.xml +++ b/ycl-server/src/main/resources/mapper/zgyw/TContractMapper.xml @@ -1,86 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper -PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" -"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.ycl.platform.mapper.TContractMapper"> - - <resultMap type="com.ycl.platform.domain.entity.TContract" id="TContractResult"> - <result property="id" column="id" /> - <result property="companyId" column="company_id" /> - <result property="companyName" column="company_name" /> - <result property="deptId" column="dept_id" /> - <result property="deptName" column="dept_name" /> - <result property="detail" column="detail" /> - <result property="startTime" column="start_time" /> - <result property="endTime" column="end_time" /> - </resultMap> - <sql id="selectTContractVo"> - select id, company_id, company_name, dept_id, dept_name, detail ,start_time,end_time from t_contract - </sql> - - <select id="selectTContractList" parameterType="com.ycl.platform.domain.entity.TContract" resultMap="TContractResult"> - <include refid="selectTContractVo"/> - <where> - <if test="companyId != null "> and company_id = #{companyId}</if> - <if test="companyName != null and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if> - <if test="deptId != null "> and dept_id = #{deptId}</if> - <if test="deptName != null and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if> - <if test="detail != null and detail != ''"> and detail = #{detail}</if> - <if test="startTime != null"> and start_time = #{startTime}</if> - <if test="endTime != null"> and end_time = #{endTime}</if> - </where> - </select> - - <select id="selectTContractById" parameterType="Long" resultMap="TContractResult"> - <include refid="selectTContractVo"/> - where id = #{id} - </select> - - <insert id="insertTContract" parameterType="com.ycl.platform.domain.entity.TContract" useGeneratedKeys="true" keyProperty="id"> - insert into t_contract - <trim prefix="(" suffix=")" suffixOverrides=","> - <if test="companyId != null">company_id,</if> - <if test="companyName != null">company_name,</if> - <if test="deptId != null">dept_id,</if> - <if test="deptName != null">dept_name,</if> - <if test="detail != null">detail,</if> - <if test="startTime != null">start_time,</if> - <if test="endTime != null">end_time,</if> - </trim> - <trim prefix="values (" suffix=")" suffixOverrides=","> - <if test="companyId != null">#{companyId},</if> - <if test="companyName != null">#{companyName},</if> - <if test="deptId != null">#{deptId},</if> - <if test="deptName != null">#{deptName},</if> - <if test="detail != null">#{detail},</if> - <if test="startTime != null">#{startTime},</if> - <if test="endTime != null">#{endTime},</if> - </trim> - </insert> - - <update id="updateTContract" parameterType="com.ycl.platform.domain.entity.TContract"> - update t_contract - <trim prefix="SET" suffixOverrides=","> - <if test="companyId != null">company_id = #{companyId},</if> - <if test="companyName != null">company_name = #{companyName},</if> - <if test="deptId != null">dept_id = #{deptId},</if> - <if test="deptName != null">dept_name = #{deptName},</if> - <if test="detail != null">detail = #{detail},</if> - <if test="startTime != null">start_time = #{startTime},</if> - <if test="endTime != null">end_time = #{endTime},</if> - </trim> - where id = #{id} - </update> - - <delete id="deleteTContractById" parameterType="Long"> - delete from t_contract where id = #{id} - </delete> - - <delete id="deleteTContractByIds" parameterType="String"> - delete from t_contract where id in - <foreach item="id" collection="array" open="(" separator="," close=")"> - #{id} - </foreach> - </delete> </mapper> \ No newline at end of file -- Gitblit v1.8.0