| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- package com.ims.eval.controller;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.ims.eval.config.CustomException;
- import com.ims.eval.entity.Indicator;
- import com.ims.eval.entity.OrganizationEvaluationInfo;
- import com.ims.eval.entity.YearGroupCoefficient;
- import com.ims.eval.entity.YearOperatingCoefficient;
- import com.ims.eval.entity.dto.request.IndicatorDictionaryDTO;
- import com.ims.eval.entity.dto.request.YearGroupCoefficientDTO;
- import com.ims.eval.entity.dto.result.R;
- import com.ims.eval.service.IIndicatorDictionaryService;
- import com.ims.eval.service.IIndicatorService;
- import com.ims.eval.service.IYearGroupCoefficientService;
- import com.ims.eval.service.IYearOperatingCoefficientService;
- import com.ims.eval.util.ExcelUtil;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletRequest;
- import java.io.InputStream;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.List;
- /**
- * <p>
- * 年度经营业绩系数明细 前端控制器
- * </p>
- *
- * @author wang
- * @since 2023-03-17
- */
- @RestController
- @RequestMapping("//year-operating-coefficient")
- public class YearOperatingCoefficientController {
- @Autowired
- private IYearOperatingCoefficientService yearOperatingCoefficientService;
- /**
- * year
- * @param pageNum
- * @param pageSize
- * @param id
- * @param organizationName
- * @param organizationId
- * @param yearGroupCoefficientId
- * @param binSection
- * @param year
- * @return
- */
- //@ImsPreAuth("eval:yearOperatingCoefficient:view")
- @GetMapping(value = "list")
- public R list(@RequestParam(value = "pageNum") Integer pageNum,
- @RequestParam(value = "pageSize") Integer pageSize,
- @RequestParam(value = "id", required = false) String id,
- @RequestParam(value = "organizationName", required = false) String organizationName,
- @RequestParam(value = "organizationId", required = false) String organizationId,
- @RequestParam(value = "yearGroupCoefficientId", required = false) String yearGroupCoefficientId,
- @RequestParam(value = "binSection", required = false) String binSection,
- @RequestParam(value = "year", required = false) String year) {
- IPage<YearOperatingCoefficient> list = yearOperatingCoefficientService.list(pageNum, pageSize, id, organizationName, organizationId, yearGroupCoefficientId, binSection,year);
- return R.ok().data(list);
- }
- /**
- * 查询所有数据
- * @param id
- * @param organizationName
- * @param organizationId
- * @param yearGroupCoefficientId
- * @param binSection
- * @param year
- * @return
- */
- //@ImsPreAuth("eval:yearOperatingCoefficient:view")
- @GetMapping(value = "listAll")
- public R listAll(
- @RequestParam(value = "id", required = false) String id,
- @RequestParam(value = "organizationName", required = false) String organizationName,
- @RequestParam(value = "organizationId", required = false) String organizationId,
- @RequestParam(value = "yearGroupCoefficientId", required = false) String yearGroupCoefficientId,
- @RequestParam(value = "binSection", required = false) String binSection,
- @RequestParam(value = "year", required = false) String year) {
- List<YearOperatingCoefficient> list = yearOperatingCoefficientService.listAll(id, organizationName, organizationId, yearGroupCoefficientId, binSection,year);
- return R.ok().data(list);
- }
- /**
- * 添加
- *
- * @param yearOperatingCoefficient
- * @return
- */
- //@ImsPreAuth("eval:yearOperatingCoefficient:edit")
- @PostMapping(value = "/save")
- @ApiOperation(value = "新增(修改)", notes = "新增(修改)")
- public R addAll(@RequestBody YearOperatingCoefficient yearOperatingCoefficient) {
- try {
- boolean b = yearOperatingCoefficientService.saveOrUpdate(yearOperatingCoefficient);
- if (b) {
- return R.ok().data(b);
- } else {
- return R.error().data("保存失败!");
- }
- } catch (CustomException e){
- return R.customError(e.getMessage()).data("失败!");
- }
- }
- /**
- * 批量删除
- *
- * @param ids
- * @return
- */
- //@ImsPreAuth("eval:yearOperatingCoefficient:remove")
- @PostMapping(value = "/remove/{ids}")
- @ApiOperation(value = "删除", notes = "删除")
- public R deleteAll(@PathVariable("ids") String ids) {
- String[] strings = ids.split(",");
- boolean b = yearOperatingCoefficientService.removeByIds(Arrays.asList(strings));
- if (b) {
- return R.ok().data(b);
- } else {
- return R.error().data("删除失败!");
- }
- }
- @PostMapping(value = "/import")
- @ResponseBody
- public R importAlertrule(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
- if (!file.isEmpty()) {
- try {
- //获取原始的文件名
- String originalFilename = file.getOriginalFilename();
- //获取文件类型
- String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length());
- //默认从第一行开始读取
- Integer startRows = 2;
- //获取输入流
- InputStream is = file.getInputStream();
- List<YearOperatingCoefficient> bindingList = new ArrayList<>();
- //Excel导入导出的单元类
- List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
- //遍历Excel表每一行的数据
- SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- for (String[] str : strings) {
- YearOperatingCoefficient y = new YearOperatingCoefficient();
- y.setId(str[0]);
- y.setOrganizationName(str[1]);
- y.setZzc(Double.parseDouble(str[2]));
- y.setK1(Double.parseDouble(str[3]));
- y.setJzs(Double.parseDouble(str[4]));
- y.setK2(Double.parseDouble(str[5]));
- y.setZmlrze(Double.parseDouble(str[6]));
- y.setFdl(Double.parseDouble(str[7]));
- y.setDdlr(Double.parseDouble(str[8]));
- y.setK3(Double.parseDouble(str[9]));
- y.setDy(Double.parseDouble(str[10]));
- y.setK4(Double.parseDouble(str[11]));
- y.setK(Double.parseDouble(str[12]));
- y.setCreateName(str[13]);
- y.setCreateTime(simpleDateFormat.parse(str[14]));
- bindingList.add(y);
- }
- boolean b = yearOperatingCoefficientService.saveOrUpdateBatch(bindingList);
- if (b) {
- return R.ok().data(b);
- } else {
- return R.error().data("保存失败!");
- }
- } catch (Exception e) {
- return R.customError(e.getMessage()).data("失败!");
- }
- }
- return R.customError("上传文件为空!");
- }
- }
|