|
@@ -0,0 +1,338 @@
|
|
|
+package org.jeecg.ctop.finance.policy.controller;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.*;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import cn.com.ctop.common.module.entity.SysUser;
|
|
|
+import cn.com.ctop.common.module.entity.UserCompany;
|
|
|
+import cn.com.ctop.common.module.mapper.SysUserMapper;
|
|
|
+import cn.com.ctop.common.module.service.IUserCompanyService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.ctop.finance.policy.entity.CwjsPolicyInfo;
|
|
|
+import org.jeecg.ctop.finance.policy.entity.CwjsPolicyProduct;
|
|
|
+import org.jeecg.ctop.finance.policy.service.ICwjsPolicyInfoService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+import org.jeecg.ctop.finance.policy.service.ICwjsPolicyProductService;
|
|
|
+import org.jeecg.ctop.finance.policy.utils.Check;
|
|
|
+import org.jeecg.modules.system.service.ISysRoleService;
|
|
|
+import org.jeecgframework.poi.excel.ExcelImportUtil;
|
|
|
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
|
+import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
|
+import org.jeecgframework.poi.excel.entity.ImportParams;
|
|
|
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 政策信息表
|
|
|
+ * @author jeecg-boot
|
|
|
+ * @date 2021-07-27
|
|
|
+ * @version V1.0
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Api(tags="政策信息表")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/finance/cwjsPolicyInfo")
|
|
|
+public class CwjsPolicyInfoController {
|
|
|
+ @Autowired
|
|
|
+ private ICwjsPolicyInfoService cwjsPolicyInfoService;
|
|
|
+ @Autowired
|
|
|
+ private ICwjsPolicyProductService cwjsPolicyProductService;
|
|
|
+ @Autowired
|
|
|
+ private ISysRoleService roleService;
|
|
|
+ @Resource
|
|
|
+ IUserCompanyService userCompanyService;
|
|
|
+ @Resource
|
|
|
+ private SysUserMapper userMapper;
|
|
|
+ /**
|
|
|
+ * 分页列表查询
|
|
|
+ * @param cwjsPolicyInfo
|
|
|
+ * @param pageNo
|
|
|
+ * @param pageSize
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="政策信息表-分页列表查询", notes="政策信息表-分页列表查询")
|
|
|
+ @GetMapping(value = "/list")
|
|
|
+ public Result<PageInfo<CwjsPolicyInfo>> queryPageList(CwjsPolicyInfo cwjsPolicyInfo,
|
|
|
+ @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
+ @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
+ HttpServletRequest req) {
|
|
|
+
|
|
|
+// LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ LoginUser user = new LoginUser();
|
|
|
+ user.setId("b161b7d9793942f980dbfe8c931cd1b0"); //a9ab18bf186c463dba715f39f9fa9267
|
|
|
+ String roleCode = roleService.getRoleCodeByUserId(user.getId());
|
|
|
+ if (roleCode.equals("admin")&&Check.isNull(cwjsPolicyInfo.getCreateUserId())) { //1.当前登录用户为管理员角色,并且没有传递销售id来精确查询。 则不触发sql的过滤条件
|
|
|
+ cwjsPolicyInfo.setCreateUserIds(null);
|
|
|
+ }else if(roleCode.equals("admin")&&!Check.isNull(cwjsPolicyInfo.getCreateUserId())){//2.当前登录用户为管理员角色,并且传递了销售的id,则需要触发
|
|
|
+ List<String> userIds = new ArrayList<>();
|
|
|
+ userIds.add(cwjsPolicyInfo.getCreateUserId());
|
|
|
+ cwjsPolicyInfo.setCreateUserIds(userIds);
|
|
|
+ }else if(roleCode.equals("saleDirector")){ //3.如果是销售总监 查询自己和手下创建的所有政策
|
|
|
+ List<SysUser> allList = userMapper.selectAllUser();
|
|
|
+ List<SysUser> mulUserList = treeCategoryData(allList, user.getId());
|
|
|
+ List<String> userIds = new ArrayList<>();
|
|
|
+ mulUserList.forEach(sysUser -> userIds.add(sysUser.getId()));
|
|
|
+ userIds.add(user.getId());
|
|
|
+ cwjsPolicyInfo.setCreateUserIds(userIds);
|
|
|
+ if(!Check.isNull(cwjsPolicyInfo.getCreateUserId())&& userIds.contains(cwjsPolicyInfo.getCreateUserId())){//总监精确查询了某个销售id的政策,那么先看这个销售是不是他的手下
|
|
|
+ List<String> newUserIds = new ArrayList<>();
|
|
|
+ newUserIds.add(cwjsPolicyInfo.getCreateUserId());
|
|
|
+ cwjsPolicyInfo.setCreateUserIds(newUserIds);
|
|
|
+ }
|
|
|
+ }else { //其他的人,谁登录看谁自己的
|
|
|
+ List<String> userIds = new ArrayList<>();
|
|
|
+ userIds.add(user.getId());
|
|
|
+ cwjsPolicyInfo.setCreateUserIds(userIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ PageHelper.startPage(pageNo,pageSize);
|
|
|
+ List<CwjsPolicyInfo> cwjsPolicyInfos = cwjsPolicyInfoService.queryPageList(cwjsPolicyInfo);
|
|
|
+ PageInfo<CwjsPolicyInfo> pageInfo = new PageInfo<>(cwjsPolicyInfos);
|
|
|
+ return Result.successMsg("成功。",pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<SysUser> treeCategoryData(List<SysUser> allList, String leaderId) {
|
|
|
+ List<SysUser> mapList = new ArrayList<>();
|
|
|
+ for (SysUser vo : allList) {
|
|
|
+ if (leaderId.equals(vo.getLeaderId())){
|
|
|
+ mapList.add(vo);
|
|
|
+ mapList.addAll(treeCategoryData(allList,vo.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return mapList;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页列表查询
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ @ApiOperation(value="政策信息表-分页列表查询", notes="政策信息表-分页列表查询")
|
|
|
+ @GetMapping(value = "/queryAeraByUserId")
|
|
|
+ public Result<UserCompany> queryAeraByUserId(String userId) {
|
|
|
+ Result<UserCompany> result = new Result<>();
|
|
|
+ UserCompany userCompany = userCompanyService.getByUserId(userId);
|
|
|
+ result.setSuccess(true);
|
|
|
+ result.setResult(userCompany);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ * @param cwjsPolicyInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="政策信息表-添加", notes="政策信息表-添加")
|
|
|
+ @PostMapping(value = "/add")
|
|
|
+ public Result<CwjsPolicyInfo> add(@RequestBody CwjsPolicyInfo cwjsPolicyInfo) {
|
|
|
+ Result<CwjsPolicyInfo> result = new Result<>();
|
|
|
+ try {
|
|
|
+ cwjsPolicyInfoService.save(cwjsPolicyInfo);
|
|
|
+ JSONArray products = cwjsPolicyInfo.getPolicyProductName();
|
|
|
+ List<CwjsPolicyProduct> policyProductList = new ArrayList<>();
|
|
|
+ products.forEach(productName -> {
|
|
|
+ CwjsPolicyProduct policyProduct = new CwjsPolicyProduct();
|
|
|
+ policyProduct.setCreateUserId(cwjsPolicyInfo.getCreateUserId());
|
|
|
+ policyProduct.setDelFlag(0);
|
|
|
+ policyProduct.setPolicyProductName((String) productName);
|
|
|
+ policyProduct.setPolicyId(cwjsPolicyInfo.getId());
|
|
|
+ policyProductList.add(policyProduct);
|
|
|
+ });
|
|
|
+ cwjsPolicyProductService.saveBatch(policyProductList);
|
|
|
+ result.success("添加成功!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(),e);
|
|
|
+ result.error500("操作失败");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ * @param cwjsPolicyInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="政策信息表-编辑", notes="政策信息表-编辑")
|
|
|
+ @PutMapping(value = "/edit")
|
|
|
+ public Result<CwjsPolicyInfo> edit(@RequestBody CwjsPolicyInfo cwjsPolicyInfo) {
|
|
|
+ Result<CwjsPolicyInfo> result = new Result<CwjsPolicyInfo>();
|
|
|
+ CwjsPolicyInfo cwjsPolicyInfoEntity = cwjsPolicyInfoService.getById(cwjsPolicyInfo.getId());
|
|
|
+ if(cwjsPolicyInfoEntity==null) {
|
|
|
+ result.error500("未找到对应实体");
|
|
|
+ }else {
|
|
|
+ boolean ok = cwjsPolicyInfoService.updateById(cwjsPolicyInfo);
|
|
|
+ if(ok) {
|
|
|
+ result.success("修改成功!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查询
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="政策信息表-通过id查询", notes="政策信息表-通过id查询")
|
|
|
+ @GetMapping(value = "/queryById")
|
|
|
+ public Result<CwjsPolicyInfo> queryById(@RequestParam(name="id",required=true) String id) throws ParseException {
|
|
|
+ Result<CwjsPolicyInfo> result = new Result<>();
|
|
|
+ CwjsPolicyInfo cwjsPolicyInfo = cwjsPolicyInfoService.getById(id);
|
|
|
+ Date startDate = DateUtils.parseDate(cwjsPolicyInfo.getPolicyStartDate(),"yyyy-MM-dd");
|
|
|
+ cwjsPolicyInfo.setPolicyStartDate(DateUtils.formatDate(startDate,"yyyy年MM月dd日"));
|
|
|
+ Date endDate = DateUtils.parseDate(cwjsPolicyInfo.getPolicyEndDate(),"yyyy-MM-dd");
|
|
|
+ cwjsPolicyInfo.setPolicyEndDate(DateUtils.formatDate(endDate,"yyyy年MM月dd日"));
|
|
|
+ List<CwjsPolicyProduct> policyProductList = cwjsPolicyProductService.queryProductsByPolicyId(id);
|
|
|
+ JSONArray jsonArr = new JSONArray();
|
|
|
+ policyProductList.forEach(policyProduct -> {
|
|
|
+ jsonArr.add(policyProduct.getPolicyProductName());
|
|
|
+ });
|
|
|
+ cwjsPolicyInfo.setPolicyProductName(jsonArr);
|
|
|
+ if(cwjsPolicyInfo==null) {
|
|
|
+ result.error500("未找到对应实体");
|
|
|
+ }else if(policyProductList==null){
|
|
|
+ result.error500("此政策的没有绑定产品,或者已绑定的产品被删除");
|
|
|
+ }else {
|
|
|
+ result.setResult(cwjsPolicyInfo);
|
|
|
+ result.setSuccess(true);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id删除
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="政策信息表-通过id删除", notes="政策信息表-通过id删除")
|
|
|
+ @DeleteMapping(value = "/delete")
|
|
|
+ public Result<?> delete(@RequestParam(name="id") String id) {
|
|
|
+ try {
|
|
|
+ cwjsPolicyInfoService.removeById(id);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("删除失败",e.getMessage());
|
|
|
+ return Result.error("删除失败!");
|
|
|
+ }
|
|
|
+ return Result.ok("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="政策信息表-批量删除", notes="政策信息表-批量删除")
|
|
|
+ @DeleteMapping(value = "/deleteBatch")
|
|
|
+ public Result<CwjsPolicyInfo> deleteBatch(@RequestParam(name="ids") String ids) {
|
|
|
+ Result<CwjsPolicyInfo> result = new Result<>();
|
|
|
+ if(ids==null || "".equals(ids.trim())) {
|
|
|
+ result.error500("参数不识别!");
|
|
|
+ }else {
|
|
|
+ this.cwjsPolicyInfoService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
+ result.success("删除成功!");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/exportXls")
|
|
|
+ public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ // Step.1 组装查询条件
|
|
|
+ QueryWrapper<CwjsPolicyInfo> queryWrapper = null;
|
|
|
+ try {
|
|
|
+ String paramsStr = request.getParameter("paramsStr");
|
|
|
+ if (oConvertUtils.isNotEmpty(paramsStr)) {
|
|
|
+ String deString = URLDecoder.decode(paramsStr, "UTF-8");
|
|
|
+ CwjsPolicyInfo cwjsPolicyInfo = JSON.parseObject(deString, CwjsPolicyInfo.class);
|
|
|
+ queryWrapper = QueryGenerator.initQueryWrapper(cwjsPolicyInfo, request.getParameterMap());
|
|
|
+ }
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ //Step.2 AutoPoi 导出Excel
|
|
|
+ ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
|
|
+ List<CwjsPolicyInfo> pageList = cwjsPolicyInfoService.list(queryWrapper);
|
|
|
+ //导出文件名称
|
|
|
+ mv.addObject(NormalExcelConstants.FILE_NAME, "政策信息表列表");
|
|
|
+ mv.addObject(NormalExcelConstants.CLASS, CwjsPolicyInfo.class);
|
|
|
+ mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("政策信息表列表数据", "导出人:Jeecg", "导出信息"));
|
|
|
+ mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
|
|
+ return mv;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过excel导入数据
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
+ public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
+ Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
+ for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
+ MultipartFile file = entity.getValue();
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
+ params.setTitleRows(2);
|
|
|
+ params.setHeadRows(1);
|
|
|
+ params.setNeedSave(true);
|
|
|
+ try {
|
|
|
+ List<CwjsPolicyInfo> listCwjsPolicyInfos = ExcelImportUtil.importExcel(file.getInputStream(), CwjsPolicyInfo.class, params);
|
|
|
+ cwjsPolicyInfoService.saveBatch(listCwjsPolicyInfos);
|
|
|
+ return Result.ok("文件导入成功!数据行数:" + listCwjsPolicyInfos.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(),e);
|
|
|
+ return Result.error("文件导入失败:"+e.getMessage());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ file.getInputStream().close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.ok("文件导入失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|