From 4f99f59668c9160ca60958b7347944def26f2228 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期日, 27 四月 2025 10:58:53 +0800 Subject: [PATCH] 回退配置 --- pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java | 293 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 293 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java new file mode 100644 index 0000000..830de5b --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java @@ -0,0 +1,293 @@ +package com.dy.pipIrrProject.divide; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.support.ExcelTypeEnum; +import com.dy.common.aop.SsoAop; +import com.dy.common.webUtil.BaseResponse; +import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.QueryResultVo; +import com.dy.common.webUtil.ResultCodeMsg; +import com.dy.pipIrrGlobal.pojoBa.BaClient; +import com.dy.pipIrrGlobal.pojoPr.PrDivide; +import com.dy.pipIrrGlobal.voPr.VoDivide; +import com.dy.pipIrrGlobal.voPr.VoDivideDetails; +import com.dy.pipIrrGlobal.voSe.VoActiveCard; +import com.dy.pipIrrProject.result.ProjectResultCode; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.*; + +/** + * @author ZhuBaoMin + * @date 2023/12/20 20:11 + * @LastEditTime 2023/12/20 20:11 + * @Description + */ + +@Slf4j +@Tag(name = "鍒嗘按鎴跨鐞�", description = "鍒嗘按鎴挎搷浣�") +@RestController +@RequestMapping(path="divide") +@RequiredArgsConstructor +public class DivideCtrl { + private final DivideSv divideSv; + + /** + * 鍒嗛〉鑾峰彇鍒嗘按鎴胯褰� + * @param vo + * @return + */ + @Operation(summary = "鑾峰緱涓�椤靛垎姘存埧璁板綍", description = "杩斿洖涓�椤靛垎姘存埧鏁版嵁") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖涓�椤靛紑鍗℃暟鎹紙BaseResponse.content:QueryResultVo[{}]锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = VoActiveCard.class))} + ) + }) + @GetMapping(path = "/getDivides") + @SsoAop() + public BaseResponse<QueryResultVo<List<VoDivide>>> getDivides(QueryVo vo){ + try { + //QueryResultVo<List<VoDivide>> res = divideSv.getDivides(vo); + //if(res.itemTotal != null && res.itemTotal > 0) { + // return BaseResponseUtils.buildSuccess(res); + //}else { + // return BaseResponseUtils.buildSuccess(ProjectResultCode.NO_DIVIDES.getMessage()); + //} + return BaseResponseUtils.buildSuccess(divideSv.getDivides(vo)); + } catch (Exception e) { + log.error("鑾峰彇寮�鍗¤褰曞紓甯�", e); + return BaseResponseUtils.buildException(e.getMessage()) ; + } + } + + /** + * 鏍规嵁鍒嗘按鎴夸富閿幏鍙栧垎姘存埧瀵硅薄 + * @param id + * @return + */ + @Operation(summary = "鑾峰緱涓�涓垎姘存埧", description = "杩斿洖涓�涓垎姘存埧鏁版嵁") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖涓�椤靛啘鎴锋暟鎹紙BaseResponse.content:QueryResultVo[{}]锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = BaClient.class))} + ) + }) + @GetMapping(path = "/getone/{id}") + @SsoAop() + //public BaseResponse<PrDivide> getOneDivide(@PathVariable("id") Long id){ + public BaseResponse<VoDivideDetails> getOneDivide(@PathVariable("id") Long id){ + try { + //PrDivide res = divideSv.getOneDivide(id); + //if(res != null) { + // return BaseResponseUtils.buildSuccess(res); + //}else { + // return BaseResponseUtils.buildErrorMsg(ProjectResultCode.NO_DIVIDES.getMessage()); + //} + return BaseResponseUtils.buildSuccess(divideSv.getDivideDetails(id)); + } catch (Exception e) { + log.error("鏌ヨ鍐滄埛寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()) ; + } + } + + /** + * 娣诲姞鍒嗘按鎴胯褰� + * @param po + * @param bindingResult + * @return + */ + @Operation(summary = "娣诲姞鍒嗘按鎴胯褰�", description = "娣诲姞鍒嗘按鎴胯褰�") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "add", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> add(@RequestBody @Valid DtoDivide po, BindingResult bindingResult){ + if(bindingResult != null && bindingResult.hasErrors()){ + return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + // 鎺ユ敹鏉戠紪鍙凤紙涓婚敭锛� + Long villageId = po.getVillageId(); + + PrDivide prDivide = DtoToDividePojo.INSTANCT.po2vo(po); + + if (villageId!=null){ + /** + * 鑾峰彇5绾ц鏀垮尯鍒掍俊鎭� + */ + Map map_districts = Optional.ofNullable(divideSv.getDistrictsByVillageId(villageId)).orElse(new HashMap()); + if(map_districts.size() <= 0) { + return BaseResponseUtils.buildErrorMsg("鍖哄垝淇℃伅鏈夎"); + } + Long countryId = Long.parseLong(map_districts.get("countryId").toString()); + Long townId = Long.parseLong(map_districts.get("townId").toString()); + prDivide.setCountyid(countryId); + prDivide.setTownid(townId); + } + + Date operateTime = new Date(); + prDivide.setOperatedt(operateTime); + prDivide.setDeleted((byte)0); + Integer rec = Optional.ofNullable(divideSv.addDivide(prDivide)).orElse(0); + if(rec == 0) { + return BaseResponseUtils.buildErrorMsg(ProjectResultCode.DIVIDE_FAIL.getMessage()); + } + return BaseResponseUtils.buildSuccess(true) ; + } + + /** + * 鏍规嵁鍒嗘按鎴縄D閫昏緫鍒犻櫎鍒嗘按鎴� + * @param map + * @return + */ + @Operation(summary = "鍒犻櫎涓�涓垎姘存埧", description = "鍒犻櫎涓�涓垎姘存埧鏁版嵁") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖涓�椤靛啘鎴锋暟鎹紙BaseResponse.content:QueryResultVo[{}]锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = BaClient.class))} + ) + }) + + //@GetMapping(path = "/delone/{id}") + @PostMapping(path = "delete", consumes = MediaType.APPLICATION_JSON_VALUE) + @SsoAop() + public BaseResponse<Boolean> deleteDivideById(@RequestBody Map map){ + Long id = Optional.ofNullable(Long.parseLong(map.get("id").toString())).orElse(0L); + if(id == 0) + return BaseResponseUtils.buildException(ProjectResultCode.DELETE_DIVIDE_FAIL.getMessage()); + + try { + Integer res = Optional.ofNullable(divideSv.deleteDivideById(id)).orElse(0); + if(res == 0) + return BaseResponseUtils.buildErrorMsg(ProjectResultCode.DELETE_DIVIDE_FAIL.getMessage()); + + return BaseResponseUtils.buildSuccess(true); + } catch (Exception e) { + log.error("鍒犻櫎鍒嗘按鎴垮紓甯�", e); + return BaseResponseUtils.buildException(e.getMessage()) ; + } + } + + /** + * 淇敼鍒嗘按鎴� + * @param po + * @param bindingResult + * @return + */ + @Operation(summary = "淇敼鍒嗘按鎴胯褰�", description = "淇敼鍒嗘按鎴胯褰�") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> update(@RequestBody @Valid DtoDivide po, BindingResult bindingResult){ + if(bindingResult != null && bindingResult.hasErrors()){ + return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + + // 鎺ユ敹鏉戠紪鍙凤紙涓婚敭锛� + Long villageId = po.getVillageId(); + + PrDivide prDivide = DtoToDividePojo.INSTANCT.po2vo(po); + + if (villageId!=null){ + /** + * 鑾峰彇5绾ц鏀垮尯鍒掍俊鎭� + */ + Map map_districts = Optional.ofNullable(divideSv.getDistrictsByVillageId(villageId)).orElse(new HashMap()); + if(map_districts.size() <= 0) { + return BaseResponseUtils.buildErrorMsg("鍖哄垝淇℃伅鏈夎"); + } + Long countryId = Long.parseLong(map_districts.get("countryId").toString()); + Long townId = Long.parseLong(map_districts.get("townId").toString()); + prDivide.setCountyid(countryId); + prDivide.setTownid(townId); + } + + Date operateTime = new Date(); + prDivide.setOperatedt(operateTime); + + Integer rec = Optional.ofNullable(divideSv.updateByPrimaryKey(prDivide)).orElse(0); + if(rec == 0) { + return BaseResponseUtils.buildErrorMsg("鍒嗘按鎴夸慨鏀瑰け璐�"); + } + return BaseResponseUtils.buildSuccess(true) ; + } + + /** + * 瀵煎嚭鍒嗘按鎴垮垪琛� + * @param response + * @param vo + */ + @SneakyThrows(IOException.class) + @RequestMapping(value = "/export", method = RequestMethod.GET) + public void export(HttpServletResponse response, QueryVo vo) { + setExcelRespProp(response, "鍒嗘按鎴垮垪琛�"); + //List<VoDivide> memberList = LocalJsonUtil.getListFromJson("json/members.json", VoDivide.class); + List<VoDivide> memberList = divideSv.exportDivides(vo); + + EasyExcel.write(response.getOutputStream()) + .head(VoDivide.class) + .excelType(ExcelTypeEnum.XLSX) + .sheet("鍒嗘按鎴垮垪琛�") + .doWrite(memberList); + } + + @SneakyThrows + @RequestMapping(value = "/importDivides", method = RequestMethod.POST) + @ResponseBody + public BaseResponse<Boolean> importDivides(@RequestPart("file") MultipartFile file) { + List<VoDivide> memberList = EasyExcel.read(file.getInputStream()) + .head(VoDivide.class) + .sheet() + .doReadSync(); + return BaseResponseUtils.buildSuccess(memberList) ; + } + + /** + * 璁剧疆excel涓嬭浇鍝嶅簲澶村睘鎬� + */ + private void setExcelRespProp(HttpServletResponse response, String rawFileName) throws UnsupportedEncodingException { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String fileName = URLEncoder.encode(rawFileName, "UTF-8").replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + } +} -- Gitblit v1.8.0