package com.product.org.admin.controller; import java.util.Date; import javax.servlet.http.HttpServletRequest; import com.product.util.BaseUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.product.org.admin.config.CmnConst; import com.product.org.admin.service.CostCenterService; import com.product.admin.config.SystemCode; import com.product.common.lang.StringUtils; import com.product.core.config.CoreConst; import com.product.core.controller.support.AbstractBaseController; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; import com.product.core.entity.RequestParameterEntity; import com.product.core.exception.BaseException; import com.product.core.permission.PermissionService; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.module.sys.config.SystemErrorCode; import com.product.module.sys.version.ApiVersion; /** * Copyright LX-BASE * * @Title: CostCenterController * @Project: LX-BASE-SERVER * @Date: 2020年10月09日 下午14:59:26 * @Author: 郑盟 * @Description:成本中心控制层 */ @RequestMapping("/api/cost_center") @RestController public class CostCenterController extends AbstractBaseController { @Autowired public CostCenterService costCenterService; @Autowired PermissionService permissionService; /** * 成本中心详情 * @param request * @return */ @RequestMapping(value = "/find-center/{varsion}", method = RequestMethod.POST) @ApiVersion(1) public String findCenter(HttpServletRequest request) { try { //获取参数 FieldSetEntity fse=null; Object bean=request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if(bean != null) { RequestParameterEntity reqp=(RequestParameterEntity)bean; fse = reqp.getFormData(); } //判断参数是否为空 if(bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } //判断传参是否为空 if (StringUtils.isEmpty(fse.getString("uuid"))) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); } //数据操作的权限验证 if(!permissionService.validDataPermission(CmnConst.PRODUCT_SYS_COST_CENTER,fse.getUUID(),CoreConst.DATA_PERMISSION_VALID_TYPE_ORG)) { SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); } FieldSetEntity fs = costCenterService.findCenter(fse); return OK_List(fs); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e.getCode(), e.getMessageInfo()); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_FIND_COST_CENTER.getValue(),SystemCode.SYSTEM_FIND_COST_CENTER.getText()+ e.getMessage()); } } /** * 新增成本中心 */ @RequestMapping(value = "/add-center/{varsion}", method = RequestMethod.POST) @ApiVersion(1) public String addCenter(HttpServletRequest request) { try { //获取参数 FieldSetEntity fse=null; Object bean=request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if(bean != null) { RequestParameterEntity reqp=(RequestParameterEntity)bean; fse = reqp.getFormData(); } //判断参数是否为空 if(bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } //添加创建创建人,创建时间 fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); //罗鑫2021年3月1日 开始时间不能大于结束时间 String effective_start_date = fse.getString("effective_start_date"); if(BaseUtil.strIsNull(effective_start_date)){ SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getValue(), SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getText()); return error(SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getValue(), SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getText()); } String effective_end_date = fse.getString("effective_end_date"); if(!BaseUtil.strIsNull(effective_end_date)) { if (BaseUtil.temporalComparison(effective_start_date, effective_end_date)) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_VALID_TIME_FAIL.getValue(), SystemCode.SYSTEM_VALID_TIME_FAIL.getText()); return error(SystemCode.SYSTEM_VALID_TIME_FAIL.getValue(), SystemCode.SYSTEM_VALID_TIME_FAIL.getText()); } } //执行新增 String uuid = costCenterService.add(fse); if (!StringUtils.isEmpty(uuid)) { return OK_Add(uuid); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_ADD_COST_CENTER.getValue(), SystemCode.SYSTEM_ADD_COST_CENTER.getText()); return error(SystemCode.SYSTEM_ADD_COST_CENTER.getValue(), SystemCode.SYSTEM_ADD_COST_CENTER.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return error(e.getCode(), e.getMessageInfo()); }catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_ADD_COST_CENTER.getValue(),SystemCode.SYSTEM_ADD_COST_CENTER.getText()+ e.getMessage()); } } /** * 修改成本中心 */ @RequestMapping(value = "/update-center/{varsion}", method = RequestMethod.POST) @ApiVersion(1) public String updateCenter(HttpServletRequest request) { try { //获取参数 FieldSetEntity fse=null; Object bean=request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if(bean != null) { RequestParameterEntity reqp=(RequestParameterEntity)bean; fse = reqp.getFormData(); } //判断参数是否为空 if(bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } //数据操作的权限验证 if(!permissionService.validDataPermission(CmnConst.PRODUCT_SYS_COST_CENTER,fse.getUUID(),CoreConst.DATA_PERMISSION_VALID_TYPE_ORG)) { SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); } //罗鑫2021年3月1日 开始时间不能大于结束时间 String effective_start_date = fse.getString("effective_start_date"); if(BaseUtil.strIsNull(effective_start_date)){ SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getValue(), SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getText()); return error(SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getValue(), SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getText()); } String effective_end_date = fse.getString("effective_end_date"); if(!BaseUtil.strIsNull(effective_end_date)) { if (BaseUtil.temporalComparison(effective_start_date, effective_end_date)) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_VALID_TIME_FAIL.getValue(), SystemCode.SYSTEM_VALID_TIME_FAIL.getText()); return error(SystemCode.SYSTEM_VALID_TIME_FAIL.getValue(), SystemCode.SYSTEM_VALID_TIME_FAIL.getText()); } } //添加修改人,修改时间 fse.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); fse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date()); //执行修改 boolean update = costCenterService.update(fse); if (update) { return OK(); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_UPDATE_COST_CENTER.getValue(),SystemCode.SYSTEM_UPDATE_COST_CENTER.getText()); return error(SystemCode.SYSTEM_UPDATE_COST_CENTER.getValue(),SystemCode.SYSTEM_UPDATE_COST_CENTER.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return error(e.getCode(), e.getMessageInfo()); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_UPDATE_COST_CENTER.getValue(),SystemCode.SYSTEM_UPDATE_COST_CENTER.getText()+ e.getMessage()); } } /** * 删除成本中心 */ @RequestMapping(value = "/delect-center/{varsion}", method = RequestMethod.POST) @ApiVersion(1) public String delectCenter(HttpServletRequest request) { try { //获取参数 FieldSetEntity fse=null; Object bean=request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if(bean != null) { RequestParameterEntity reqp=(RequestParameterEntity)bean; fse = reqp.getFormData(); } //判断参数是否为空 if(bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } //判断传参是否为空 if (StringUtils.isEmpty(fse.getString("uuid"))) { return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); } //数据操作的权限验证 if(!permissionService.validDataPermission(CmnConst.PRODUCT_SYS_COST_CENTER,fse.getUUID(),CoreConst.DATA_PERMISSION_VALID_TYPE_ORG)) { SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); } boolean delete = costCenterService.deleteCenter(fse); if (delete) { return OK(); } SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_DELETE_COST_CENTER.getValue(),SystemCode.SYSTEM_DELETE_COST_CENTER.getText()); return error(SystemCode.SYSTEM_DELETE_COST_CENTER.getValue(),SystemCode.SYSTEM_DELETE_COST_CENTER.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e.getCode(), e.getMessageInfo()); }catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_DELETE_COST_CENTER.getValue(),SystemCode.SYSTEM_DELETE_COST_CENTER.getText()+ e.getMessage()); } } /** * 成本中心列表 */ @RequestMapping(value = "/list-center/{varsion}", method = RequestMethod.POST) @ApiVersion(1) public String listCenter(HttpServletRequest request) { try { //获取参数 FieldSetEntity fse=null; Object bean=request.getAttribute(CoreConst.API_POST_REQUEST_DATA); if(bean != null) { RequestParameterEntity reqp=(RequestParameterEntity)bean; fse = reqp.getFormData(); } //判断参数是否为空 if(bean == null || fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } DataTableEntity fs = costCenterService.listCenter(fse); return OK_List(fs); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); return this.error(e.getCode(), e.getMessageInfo()); }catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(SystemCode.SYSTEM_FIND_COST_CENTER.getValue(),SystemCode.SYSTEM_FIND_COST_CENTER.getText()+ e.getMessage()); } } }