YearOperatingCoefficientController.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package com.ims.eval.controller;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.ims.eval.config.CustomException;
  4. import com.ims.eval.entity.Indicator;
  5. import com.ims.eval.entity.OrganizationEvaluationInfo;
  6. import com.ims.eval.entity.YearGroupCoefficient;
  7. import com.ims.eval.entity.YearOperatingCoefficient;
  8. import com.ims.eval.entity.dto.request.IndicatorDictionaryDTO;
  9. import com.ims.eval.entity.dto.request.YearGroupCoefficientDTO;
  10. import com.ims.eval.entity.dto.result.R;
  11. import com.ims.eval.service.IIndicatorDictionaryService;
  12. import com.ims.eval.service.IIndicatorService;
  13. import com.ims.eval.service.IYearGroupCoefficientService;
  14. import com.ims.eval.service.IYearOperatingCoefficientService;
  15. import com.ims.eval.util.ExcelUtil;
  16. import io.swagger.annotations.ApiOperation;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import javax.servlet.http.HttpServletRequest;
  21. import java.io.InputStream;
  22. import java.text.SimpleDateFormat;
  23. import java.util.ArrayList;
  24. import java.util.Arrays;
  25. import java.util.Date;
  26. import java.util.List;
  27. /**
  28. * <p>
  29. * 年度经营业绩系数明细 前端控制器
  30. * </p>
  31. *
  32. * @author wang
  33. * @since 2023-03-17
  34. */
  35. @RestController
  36. @RequestMapping("//year-operating-coefficient")
  37. public class YearOperatingCoefficientController {
  38. @Autowired
  39. private IYearOperatingCoefficientService yearOperatingCoefficientService;
  40. /**
  41. * year
  42. * @param pageNum
  43. * @param pageSize
  44. * @param id
  45. * @param organizationName
  46. * @param organizationId
  47. * @param yearGroupCoefficientId
  48. * @param binSection
  49. * @param year
  50. * @return
  51. */
  52. //@ImsPreAuth("eval:yearOperatingCoefficient:view")
  53. @GetMapping(value = "list")
  54. public R list(@RequestParam(value = "pageNum") Integer pageNum,
  55. @RequestParam(value = "pageSize") Integer pageSize,
  56. @RequestParam(value = "id", required = false) String id,
  57. @RequestParam(value = "organizationName", required = false) String organizationName,
  58. @RequestParam(value = "organizationId", required = false) String organizationId,
  59. @RequestParam(value = "yearGroupCoefficientId", required = false) String yearGroupCoefficientId,
  60. @RequestParam(value = "binSection", required = false) String binSection,
  61. @RequestParam(value = "year", required = false) String year) {
  62. IPage<YearOperatingCoefficient> list = yearOperatingCoefficientService.list(pageNum, pageSize, id, organizationName, organizationId, yearGroupCoefficientId, binSection,year);
  63. return R.ok().data(list);
  64. }
  65. /**
  66. * 查询所有数据
  67. * @param id
  68. * @param organizationName
  69. * @param organizationId
  70. * @param yearGroupCoefficientId
  71. * @param binSection
  72. * @param year
  73. * @return
  74. */
  75. //@ImsPreAuth("eval:yearOperatingCoefficient:view")
  76. @GetMapping(value = "listAll")
  77. public R listAll(
  78. @RequestParam(value = "id", required = false) String id,
  79. @RequestParam(value = "organizationName", required = false) String organizationName,
  80. @RequestParam(value = "organizationId", required = false) String organizationId,
  81. @RequestParam(value = "yearGroupCoefficientId", required = false) String yearGroupCoefficientId,
  82. @RequestParam(value = "binSection", required = false) String binSection,
  83. @RequestParam(value = "year", required = false) String year) {
  84. List<YearOperatingCoefficient> list = yearOperatingCoefficientService.listAll(id, organizationName, organizationId, yearGroupCoefficientId, binSection,year);
  85. return R.ok().data(list);
  86. }
  87. /**
  88. * 添加
  89. *
  90. * @param yearOperatingCoefficient
  91. * @return
  92. */
  93. //@ImsPreAuth("eval:yearOperatingCoefficient:edit")
  94. @PostMapping(value = "/save")
  95. @ApiOperation(value = "新增(修改)", notes = "新增(修改)")
  96. public R addAll(@RequestBody YearOperatingCoefficient yearOperatingCoefficient) {
  97. try {
  98. boolean b = yearOperatingCoefficientService.saveOrUpdate(yearOperatingCoefficient);
  99. if (b) {
  100. return R.ok().data(b);
  101. } else {
  102. return R.error().data("保存失败!");
  103. }
  104. } catch (CustomException e){
  105. return R.customError(e.getMessage()).data("失败!");
  106. }
  107. }
  108. /**
  109. * 批量删除
  110. *
  111. * @param ids
  112. * @return
  113. */
  114. //@ImsPreAuth("eval:yearOperatingCoefficient:remove")
  115. @PostMapping(value = "/remove/{ids}")
  116. @ApiOperation(value = "删除", notes = "删除")
  117. public R deleteAll(@PathVariable("ids") String ids) {
  118. String[] strings = ids.split(",");
  119. boolean b = yearOperatingCoefficientService.removeByIds(Arrays.asList(strings));
  120. if (b) {
  121. return R.ok().data(b);
  122. } else {
  123. return R.error().data("删除失败!");
  124. }
  125. }
  126. @PostMapping(value = "/import")
  127. @ResponseBody
  128. public R importAlertrule(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
  129. if (!file.isEmpty()) {
  130. try {
  131. //获取原始的文件名
  132. String originalFilename = file.getOriginalFilename();
  133. //获取文件类型
  134. String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length());
  135. //默认从第一行开始读取
  136. Integer startRows = 2;
  137. //获取输入流
  138. InputStream is = file.getInputStream();
  139. List<YearOperatingCoefficient> bindingList = new ArrayList<>();
  140. //Excel导入导出的单元类
  141. List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
  142. //遍历Excel表每一行的数据
  143. SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  144. for (String[] str : strings) {
  145. YearOperatingCoefficient y = new YearOperatingCoefficient();
  146. y.setId(str[0]);
  147. y.setOrganizationName(str[1]);
  148. y.setZzc(Double.parseDouble(str[2]));
  149. y.setK1(Double.parseDouble(str[3]));
  150. y.setJzs(Double.parseDouble(str[4]));
  151. y.setK2(Double.parseDouble(str[5]));
  152. y.setZmlrze(Double.parseDouble(str[6]));
  153. y.setFdl(Double.parseDouble(str[7]));
  154. y.setDdlr(Double.parseDouble(str[8]));
  155. y.setK3(Double.parseDouble(str[9]));
  156. y.setDy(Double.parseDouble(str[10]));
  157. y.setK4(Double.parseDouble(str[11]));
  158. y.setK(Double.parseDouble(str[12]));
  159. y.setCreateName(str[13]);
  160. y.setCreateTime(simpleDateFormat.parse(str[14]));
  161. bindingList.add(y);
  162. }
  163. boolean b = yearOperatingCoefficientService.saveOrUpdateBatch(bindingList);
  164. if (b) {
  165. return R.ok().data(b);
  166. } else {
  167. return R.error().data("保存失败!");
  168. }
  169. } catch (Exception e) {
  170. return R.customError(e.getMessage()).data("失败!");
  171. }
  172. }
  173. return R.customError("上传文件为空!");
  174. }
  175. }