OvertimepayStrategyController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. package cn.com.lzt.overtimepaystrategy.controller;
  2. import cn.com.lzt.dingding.service.DingdingService;
  3. import cn.com.lzt.overtimepaystrategy.entity.OvertimepayStrategyEntity;
  4. import cn.com.lzt.overtimepaystrategy.service.OvertimepayStrategyServiceI;
  5. import org.apache.log4j.Logger;
  6. import org.jeecgframework.core.beanvalidator.BeanValidators;
  7. import org.jeecgframework.core.common.controller.BaseController;
  8. import org.jeecgframework.core.common.exception.BusinessException;
  9. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  10. import org.jeecgframework.core.common.model.json.AjaxJson;
  11. import org.jeecgframework.core.common.model.json.DataGrid;
  12. import org.jeecgframework.core.constant.Globals;
  13. import org.jeecgframework.core.util.ExceptionUtil;
  14. import org.jeecgframework.core.util.MyBeanUtils;
  15. import org.jeecgframework.core.util.ResourceUtil;
  16. import org.jeecgframework.core.util.StringUtil;
  17. import org.jeecgframework.poi.excel.ExcelImportUtil;
  18. import org.jeecgframework.poi.excel.entity.ExportParams;
  19. import org.jeecgframework.poi.excel.entity.ImportParams;
  20. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  21. import org.jeecgframework.tag.core.easyui.TagUtil;
  22. import org.jeecgframework.web.system.service.SystemService;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.http.HttpHeaders;
  25. import org.springframework.http.HttpStatus;
  26. import org.springframework.http.MediaType;
  27. import org.springframework.http.ResponseEntity;
  28. import org.springframework.stereotype.Controller;
  29. import org.springframework.ui.ModelMap;
  30. import org.springframework.web.bind.annotation.*;
  31. import org.springframework.web.multipart.MultipartFile;
  32. import org.springframework.web.multipart.MultipartHttpServletRequest;
  33. import org.springframework.web.servlet.ModelAndView;
  34. import org.springframework.web.util.UriComponentsBuilder;
  35. import javax.servlet.http.HttpServletRequest;
  36. import javax.servlet.http.HttpServletResponse;
  37. import javax.validation.ConstraintViolation;
  38. import javax.validation.Validator;
  39. import java.io.IOException;
  40. import java.net.URI;
  41. import java.util.*;
  42. /**
  43. * @Title: Controller
  44. * @Description: 加班费策略表
  45. * @author onlineGenerator
  46. * @date 2017-10-09 15:29:18
  47. * @version V1.0
  48. *
  49. */
  50. @Controller
  51. @RequestMapping("/overtimepayStrategyController")
  52. public class OvertimepayStrategyController extends BaseController {
  53. /**
  54. * Logger for this class
  55. */
  56. private static final Logger logger = Logger.getLogger(OvertimepayStrategyController.class);
  57. @Autowired
  58. private OvertimepayStrategyServiceI overtimepayStrategyService;
  59. @Autowired
  60. private SystemService systemService;
  61. @Autowired
  62. private Validator validator;
  63. @Autowired
  64. private DingdingService dingdingService;
  65. /**
  66. * 加班费策略表列表 页面跳转
  67. *
  68. * @return
  69. */
  70. @RequestMapping(params = "list")
  71. public ModelAndView list(HttpServletRequest request) {
  72. return new ModelAndView("cn/com/lzt/overtimepaystrategy/overtimepayStrategyList");
  73. }
  74. /**
  75. * easyui AJAX请求数据
  76. *
  77. * @param request
  78. * @param response
  79. * @param dataGrid
  80. * @param user
  81. */
  82. @RequestMapping(params = "datagrid")
  83. public void datagrid(OvertimepayStrategyEntity overtimepayStrategy,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  84. CriteriaQuery cq = new CriteriaQuery(OvertimepayStrategyEntity.class, dataGrid);
  85. //查询条件组装器
  86. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, overtimepayStrategy, request.getParameterMap());
  87. try{
  88. //自定义追加查询条件
  89. cq.notEq("deleteFlag", Globals.Delete_Forbidden.toString());
  90. String sort = dataGrid.getSort(); // 排序对象
  91. if (StringUtil.isEmpty(sort)) {
  92. Map<String, Object> orderMap = new HashMap<String, Object>();
  93. orderMap.put("createDate", "desc");
  94. cq.setOrder(orderMap);
  95. }
  96. }catch (Exception e) {
  97. throw new BusinessException(e.getMessage());
  98. }
  99. cq.add();
  100. this.overtimepayStrategyService.getDataGridReturn(cq, true);
  101. TagUtil.datagrid(response, dataGrid);
  102. }
  103. /**
  104. * 保存新增/更新的行数据
  105. * @param page
  106. * @return
  107. */
  108. @RequestMapping(params = "saveRows")
  109. @ResponseBody
  110. public AjaxJson saveRows(OvertimepayStrategyEntity overtimepayStrategy, HttpServletRequest request){
  111. String message = null;
  112. AjaxJson j = new AjaxJson();
  113. message = "";
  114. if (StringUtil.isNotEmpty(overtimepayStrategy.getId())) {
  115. // 判断是否重复
  116. String overtimepayStrategyHqlString = "from OvertimepayStrategyEntity where id <> ? and strategyName =? and multiple =? and deleteFlag <> 1";
  117. List<OvertimepayStrategyEntity> overtimepayStrategyEntityList = overtimepayStrategyService.findHql(overtimepayStrategyHqlString, overtimepayStrategy.getId(), overtimepayStrategy.getStrategyName(), overtimepayStrategy.getMultiple());
  118. if(overtimepayStrategyEntityList.size() > 0) {
  119. message = "加班费策略重复,更新失败";
  120. j.setMsg(message);
  121. j.setSuccess(false);
  122. return j;
  123. }
  124. OvertimepayStrategyEntity t = overtimepayStrategyService.get(OvertimepayStrategyEntity.class, overtimepayStrategy.getId());
  125. try {
  126. MyBeanUtils.copyBeanNotNull2Bean(overtimepayStrategy, t);
  127. overtimepayStrategyService.saveOrUpdate(t);
  128. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  129. message = "加班费策略更新成功";
  130. j.setSuccess(true);
  131. } catch (Exception e) {
  132. e.printStackTrace();
  133. message = "加班费策略更新失败";
  134. j.setSuccess(false);
  135. throw new BusinessException(e.getMessage());
  136. }
  137. } else {
  138. // 判断是否重复
  139. String overtimepayStrategyHqlString = "from OvertimepayStrategyEntity where strategyName =? and multiple =? and deleteFlag <> 1";
  140. List<OvertimepayStrategyEntity> overtimepayStrategyEntityList = overtimepayStrategyService.findHql(overtimepayStrategyHqlString, overtimepayStrategy.getStrategyName(), overtimepayStrategy.getMultiple());
  141. if(overtimepayStrategyEntityList.size() > 0) {
  142. message = "加班费策略重复,添加失败";
  143. j.setMsg(message);
  144. j.setSuccess(false);
  145. return j;
  146. }
  147. try{
  148. overtimepayStrategy.setDeleteFlag(Globals.Delete_Normal.toString());
  149. overtimepayStrategy.setStatus(Globals.Enabled_Status.toString());
  150. overtimepayStrategyService.save(overtimepayStrategy);
  151. message = "加班费策略添加成功";
  152. j.setSuccess(true);
  153. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  154. }catch(Exception e){
  155. e.printStackTrace();
  156. message = "加班费策略添加失败";
  157. j.setSuccess(false);
  158. throw new BusinessException(e.getMessage());
  159. }
  160. }
  161. j.setMsg(message);
  162. return j;
  163. }
  164. /**
  165. * 批量逻辑删除加班费策略表
  166. *
  167. * @return
  168. */
  169. @RequestMapping(params = "doBatchLogicDel")
  170. @ResponseBody
  171. public AjaxJson doBatchLogicDel(String ids,HttpServletRequest request){
  172. String message = null;
  173. AjaxJson j = new AjaxJson();
  174. message = "加班费策略表删除成功";
  175. try{
  176. for(String id:ids.split(",")){
  177. OvertimepayStrategyEntity overtimepayStrategy = systemService.getEntity(OvertimepayStrategyEntity.class, id);
  178. overtimepayStrategy.setDeleteFlag(Globals.Delete_Forbidden.toString());
  179. overtimepayStrategyService.saveOrUpdate(overtimepayStrategy);
  180. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  181. j.setSuccess(true);
  182. }
  183. }catch(Exception e){
  184. e.printStackTrace();
  185. message = "加班费策略表删除失败";
  186. j.setSuccess(false);
  187. throw new BusinessException(e.getMessage());
  188. }
  189. j.setMsg(message);
  190. return j;
  191. }
  192. /**
  193. * 启用加班费策略
  194. *
  195. * @return
  196. */
  197. @RequestMapping(params = "doEnableObj")
  198. @ResponseBody
  199. public AjaxJson doEnableObj(String ids,HttpServletRequest request){
  200. String message = null;
  201. AjaxJson j = new AjaxJson();
  202. message = "加班费策略启用成功";
  203. try{
  204. for(String id:ids.split(",")){
  205. OvertimepayStrategyEntity overtimepayStrategy = systemService.getEntity(OvertimepayStrategyEntity.class, id);
  206. overtimepayStrategy.setStatus(Globals.Enabled_Status.toString());
  207. overtimepayStrategyService.saveOrUpdate(overtimepayStrategy);
  208. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  209. j.setSuccess(true);
  210. }
  211. }catch(Exception e){
  212. e.printStackTrace();
  213. message = "加班费策略启用失败";
  214. j.setSuccess(false);
  215. throw new BusinessException(e.getMessage());
  216. }
  217. j.setMsg(message);
  218. return j;
  219. }
  220. /**
  221. * 停用加班费策略
  222. *
  223. * @return
  224. */
  225. @RequestMapping(params = "doDisableObj")
  226. @ResponseBody
  227. public AjaxJson doDisableObj(String ids,HttpServletRequest request){
  228. String message = null;
  229. AjaxJson j = new AjaxJson();
  230. message = "加班费策略停用成功";
  231. try{
  232. for(String id:ids.split(",")){
  233. OvertimepayStrategyEntity overtimepayStrategy = systemService.getEntity(OvertimepayStrategyEntity.class, id);
  234. overtimepayStrategy.setStatus(Globals.Disabled_Status.toString());
  235. overtimepayStrategyService.saveOrUpdate(overtimepayStrategy);
  236. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  237. j.setSuccess(true);
  238. }
  239. }catch(Exception e){
  240. e.printStackTrace();
  241. message = "加班费策略停用失败";
  242. j.setSuccess(false);
  243. throw new BusinessException(e.getMessage());
  244. }
  245. j.setMsg(message);
  246. return j;
  247. }
  248. /**
  249. * 添加加班费策略表
  250. *
  251. * @param ids
  252. * @return
  253. */
  254. @RequestMapping(params = "doAdd")
  255. @ResponseBody
  256. public AjaxJson doAdd(OvertimepayStrategyEntity overtimepayStrategy, HttpServletRequest request) {
  257. String message = null;
  258. AjaxJson j = new AjaxJson();
  259. message = "加班费策略表添加成功";
  260. try{
  261. overtimepayStrategy.setDeleteFlag(Globals.Delete_Normal.toString());
  262. overtimepayStrategy.setStatus(Globals.Enabled_Status.toString());
  263. overtimepayStrategyService.save(overtimepayStrategy);
  264. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  265. }catch(Exception e){
  266. e.printStackTrace();
  267. message = "加班费策略表添加失败";
  268. throw new BusinessException(e.getMessage());
  269. }
  270. j.setMsg(message);
  271. return j;
  272. }
  273. /**
  274. * 更新加班费策略表
  275. *
  276. * @param ids
  277. * @return
  278. */
  279. @RequestMapping(params = "doUpdate")
  280. @ResponseBody
  281. public AjaxJson doUpdate(OvertimepayStrategyEntity overtimepayStrategy, HttpServletRequest request) {
  282. String message = null;
  283. AjaxJson j = new AjaxJson();
  284. message = "加班费策略表更新成功";
  285. OvertimepayStrategyEntity t = overtimepayStrategyService.get(OvertimepayStrategyEntity.class, overtimepayStrategy.getId());
  286. try {
  287. MyBeanUtils.copyBeanNotNull2Bean(overtimepayStrategy, t);
  288. overtimepayStrategyService.saveOrUpdate(t);
  289. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  290. } catch (Exception e) {
  291. e.printStackTrace();
  292. message = "加班费策略表更新失败";
  293. throw new BusinessException(e.getMessage());
  294. }
  295. j.setMsg(message);
  296. return j;
  297. }
  298. /**
  299. * 删除加班费策略表
  300. *
  301. * @return
  302. */
  303. @RequestMapping(params = "doDel")
  304. @ResponseBody
  305. public AjaxJson doDel(OvertimepayStrategyEntity overtimepayStrategy, HttpServletRequest request) {
  306. String message = null;
  307. AjaxJson j = new AjaxJson();
  308. overtimepayStrategy = systemService.getEntity(OvertimepayStrategyEntity.class, overtimepayStrategy.getId());
  309. message = "加班费策略表删除成功";
  310. try{
  311. overtimepayStrategyService.delete(overtimepayStrategy);
  312. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  313. }catch(Exception e){
  314. e.printStackTrace();
  315. message = "加班费策略表删除失败";
  316. throw new BusinessException(e.getMessage());
  317. }
  318. j.setMsg(message);
  319. return j;
  320. }
  321. /**
  322. * 批量删除加班费策略表
  323. *
  324. * @return
  325. */
  326. @RequestMapping(params = "doBatchDel")
  327. @ResponseBody
  328. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  329. String message = null;
  330. AjaxJson j = new AjaxJson();
  331. message = "加班费策略表删除成功";
  332. try{
  333. for(String id:ids.split(",")){
  334. OvertimepayStrategyEntity overtimepayStrategy = systemService.getEntity(OvertimepayStrategyEntity.class,
  335. id
  336. );
  337. overtimepayStrategyService.delete(overtimepayStrategy);
  338. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  339. }
  340. }catch(Exception e){
  341. e.printStackTrace();
  342. message = "加班费策略表删除失败";
  343. throw new BusinessException(e.getMessage());
  344. }
  345. j.setMsg(message);
  346. return j;
  347. }
  348. /**
  349. * 加班费策略表新增页面跳转
  350. *
  351. * @return
  352. */
  353. @RequestMapping(params = "goAdd")
  354. public ModelAndView goAdd(OvertimepayStrategyEntity overtimepayStrategy, HttpServletRequest req) {
  355. if (StringUtil.isNotEmpty(overtimepayStrategy.getId())) {
  356. overtimepayStrategy = overtimepayStrategyService.getEntity(OvertimepayStrategyEntity.class, overtimepayStrategy.getId());
  357. req.setAttribute("overtimepayStrategyPage", overtimepayStrategy);
  358. }
  359. return new ModelAndView("cn/com/lzt/overtimepaystrategy/overtimepayStrategy-add");
  360. }
  361. /**
  362. * 加班费策略表编辑页面跳转
  363. *
  364. * @return
  365. */
  366. @RequestMapping(params = "goUpdate")
  367. public ModelAndView goUpdate(OvertimepayStrategyEntity overtimepayStrategy, HttpServletRequest req) {
  368. if (StringUtil.isNotEmpty(overtimepayStrategy.getId())) {
  369. overtimepayStrategy = overtimepayStrategyService.getEntity(OvertimepayStrategyEntity.class, overtimepayStrategy.getId());
  370. req.setAttribute("overtimepayStrategyPage", overtimepayStrategy);
  371. }
  372. return new ModelAndView("cn/com/lzt/overtimepaystrategy/overtimepayStrategy-update");
  373. }
  374. /**
  375. * 导入功能跳转
  376. *
  377. * @return
  378. */
  379. @RequestMapping(params = "upload")
  380. public ModelAndView upload(HttpServletRequest req) {
  381. req.setAttribute("controller_name","overtimepayStrategyController");
  382. return new ModelAndView("common/upload/pub_excel_upload");
  383. }
  384. /**
  385. * 导出excel
  386. *
  387. * @param request
  388. * @param response
  389. */
  390. @RequestMapping(params = "exportXls")
  391. public String exportXls(OvertimepayStrategyEntity overtimepayStrategy,HttpServletRequest request,HttpServletResponse response
  392. , DataGrid dataGrid,ModelMap modelMap) {
  393. CriteriaQuery cq = new CriteriaQuery(OvertimepayStrategyEntity.class, dataGrid);
  394. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, overtimepayStrategy, request.getParameterMap());
  395. List<OvertimepayStrategyEntity> overtimepayStrategys = this.overtimepayStrategyService.getListByCriteriaQuery(cq,false);
  396. modelMap.put(NormalExcelConstants.FILE_NAME,"加班费策略表");
  397. modelMap.put(NormalExcelConstants.CLASS,OvertimepayStrategyEntity.class);
  398. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("加班费策略表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  399. "导出信息"));
  400. modelMap.put(NormalExcelConstants.DATA_LIST,overtimepayStrategys);
  401. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  402. }
  403. /**
  404. * 导出excel 使模板
  405. *
  406. * @param request
  407. * @param response
  408. */
  409. @RequestMapping(params = "exportXlsByT")
  410. public String exportXlsByT(OvertimepayStrategyEntity overtimepayStrategy,HttpServletRequest request,HttpServletResponse response
  411. , DataGrid dataGrid,ModelMap modelMap) {
  412. modelMap.put(NormalExcelConstants.FILE_NAME,"加班费策略表");
  413. modelMap.put(NormalExcelConstants.CLASS,OvertimepayStrategyEntity.class);
  414. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("加班费策略表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  415. "导出信息"));
  416. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  417. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  418. }
  419. @SuppressWarnings("unchecked")
  420. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  421. @ResponseBody
  422. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  423. AjaxJson j = new AjaxJson();
  424. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  425. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  426. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  427. MultipartFile file = entity.getValue();// 获取上传文件对象
  428. ImportParams params = new ImportParams();
  429. params.setTitleRows(2);
  430. params.setHeadRows(1);
  431. params.setNeedSave(true);
  432. try {
  433. List<OvertimepayStrategyEntity> listOvertimepayStrategyEntitys = ExcelImportUtil.importExcel(file.getInputStream(),OvertimepayStrategyEntity.class,params);
  434. for (OvertimepayStrategyEntity overtimepayStrategy : listOvertimepayStrategyEntitys) {
  435. overtimepayStrategyService.save(overtimepayStrategy);
  436. }
  437. j.setMsg("文件导入成功!");
  438. } catch (Exception e) {
  439. j.setMsg("文件导入失败!");
  440. logger.error(ExceptionUtil.getExceptionMessage(e));
  441. }finally{
  442. try {
  443. file.getInputStream().close();
  444. } catch (IOException e) {
  445. e.printStackTrace();
  446. }
  447. }
  448. }
  449. return j;
  450. }
  451. @RequestMapping(method = RequestMethod.GET)
  452. @ResponseBody
  453. public List<OvertimepayStrategyEntity> list() {
  454. List<OvertimepayStrategyEntity> listOvertimepayStrategys=overtimepayStrategyService.getList(OvertimepayStrategyEntity.class);
  455. return listOvertimepayStrategys;
  456. }
  457. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  458. @ResponseBody
  459. public ResponseEntity<?> get(@PathVariable("id") String id) {
  460. OvertimepayStrategyEntity task = overtimepayStrategyService.get(OvertimepayStrategyEntity.class, id);
  461. if (task == null) {
  462. return new ResponseEntity(HttpStatus.NOT_FOUND);
  463. }
  464. return new ResponseEntity(task, HttpStatus.OK);
  465. }
  466. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  467. @ResponseBody
  468. public ResponseEntity<?> create(@RequestBody OvertimepayStrategyEntity overtimepayStrategy, UriComponentsBuilder uriBuilder) {
  469. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  470. Set<ConstraintViolation<OvertimepayStrategyEntity>> failures = validator.validate(overtimepayStrategy);
  471. if (!failures.isEmpty()) {
  472. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  473. }
  474. //保存
  475. try{
  476. overtimepayStrategyService.save(overtimepayStrategy);
  477. } catch (Exception e) {
  478. e.printStackTrace();
  479. return new ResponseEntity(HttpStatus.NO_CONTENT);
  480. }
  481. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  482. String id = overtimepayStrategy.getId();
  483. URI uri = uriBuilder.path("/rest/overtimepayStrategyController/" + id).build().toUri();
  484. HttpHeaders headers = new HttpHeaders();
  485. headers.setLocation(uri);
  486. return new ResponseEntity(headers, HttpStatus.CREATED);
  487. }
  488. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  489. public ResponseEntity<?> update(@RequestBody OvertimepayStrategyEntity overtimepayStrategy) {
  490. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  491. Set<ConstraintViolation<OvertimepayStrategyEntity>> failures = validator.validate(overtimepayStrategy);
  492. if (!failures.isEmpty()) {
  493. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  494. }
  495. //保存
  496. try{
  497. overtimepayStrategyService.saveOrUpdate(overtimepayStrategy);
  498. } catch (Exception e) {
  499. e.printStackTrace();
  500. return new ResponseEntity(HttpStatus.NO_CONTENT);
  501. }
  502. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  503. return new ResponseEntity(HttpStatus.NO_CONTENT);
  504. }
  505. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  506. @ResponseStatus(HttpStatus.NO_CONTENT)
  507. public void delete(@PathVariable("id") String id) {
  508. overtimepayStrategyService.deleteEntityById(OvertimepayStrategyEntity.class, id);
  509. }
  510. }