| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564 |
- package cn.com.lzt.clothing.user.controller;
- import cn.com.lzt.arrangeduty.dto.UserOrgDto;
- import cn.com.lzt.clothing.base.entity.ClothingEntity;
- import cn.com.lzt.clothing.onhand.service.ClothingOnhandServiceI;
- import cn.com.lzt.clothing.user.entity.ClothingUserEntity;
- import cn.com.lzt.clothing.user.entity.ClothingUserInitPage;
- import cn.com.lzt.clothing.user.service.ClothingUserServiceI;
- import cn.com.lzt.dialogDeal.service.UserDepartOrgDealServiceI;
- import cn.com.lzt.post.entity.PostEntity;
- import cn.com.lzt.warehouse.entity.WarehouseEntity;
- import org.apache.log4j.Logger;
- import org.jeecgframework.core.beanvalidator.BeanValidators;
- import org.jeecgframework.core.common.controller.BaseController;
- import org.jeecgframework.core.common.exception.BusinessException;
- import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
- import org.jeecgframework.core.common.model.json.AjaxJson;
- import org.jeecgframework.core.common.model.json.DataGrid;
- import org.jeecgframework.core.constant.Globals;
- import org.jeecgframework.core.util.ExceptionUtil;
- import org.jeecgframework.core.util.MyBeanUtils;
- import org.jeecgframework.core.util.ResourceUtil;
- import org.jeecgframework.core.util.StringUtil;
- import org.jeecgframework.poi.excel.ExcelImportUtil;
- import org.jeecgframework.poi.excel.entity.ExportParams;
- import org.jeecgframework.poi.excel.entity.ImportParams;
- import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
- import org.jeecgframework.tag.core.easyui.TagUtil;
- import org.jeecgframework.web.system.pojo.base.TSDepart;
- import org.jeecgframework.web.system.pojo.base.TSUser;
- import org.jeecgframework.web.system.service.SystemService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.HttpHeaders;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.MediaType;
- import org.springframework.http.ResponseEntity;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- 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 org.springframework.web.util.UriComponentsBuilder;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.validation.ConstraintViolation;
- import javax.validation.Validator;
- import java.io.IOException;
- import java.net.URI;
- import java.util.*;
- /**
- * @Title: Controller
- * @Description: 人员服装使用表
- * @author onlineGenerator
- * @date 2019-10-08 14:43:22
- * @version V1.0
- *
- */
- @Controller
- @RequestMapping("/clothingUserController")
- public class ClothingUserController extends BaseController {
- /**
- * Logger for this class
- */
- private static final Logger logger = Logger.getLogger(ClothingUserController.class);
- @Autowired
- private ClothingUserServiceI clothingUserService;
- @Autowired
- private SystemService systemService;
- @Autowired
- private Validator validator;
- @Autowired
- private ClothingOnhandServiceI onhandService;
- @Autowired
- private UserDepartOrgDealServiceI userOrgdao;
- /**
- * 人员服装使用表列表 页面跳转
- *
- * @return
- */
- @RequestMapping(params = "list")
- public ModelAndView list(HttpServletRequest request) {
- String userid = request.getParameter("userid");
- request.setAttribute("userid", userid);
- return new ModelAndView("cn/com/lzt/clothing/user/clothingUserList");
- }
- /**
- * easyui AJAX请求数据
- *
- * @param request
- * @param response
- * @param dataGrid
- * @param user
- */
- @RequestMapping(params = "datagrid")
- public void datagrid(ClothingUserEntity clothingUser,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- CriteriaQuery cq = new CriteriaQuery(ClothingUserEntity.class, dataGrid);
- //查询条件组装器
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, clothingUser, request.getParameterMap());
- try{
- //自定义追加查询条件
- }catch (Exception e) {
- throw new BusinessException(e.getMessage());
- }
- cq.add();
- this.clothingUserService.getDataGridReturn(cq, true);
- TagUtil.datagrid(response, dataGrid);
- }
-
- /**
- * 删除人员服装使用表
- *
- * @return
- */
- @RequestMapping(params = "doDel")
- @ResponseBody
- public AjaxJson doDel(ClothingUserEntity clothingUser, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- clothingUser = systemService.getEntity(ClothingUserEntity.class, clothingUser.getId());
- message = "人员服装使用表删除成功";
- try{
- clothingUserService.delete(clothingUser);
- systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
- }catch(Exception e){
- e.printStackTrace();
- message = "人员服装使用表删除失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
-
- /**
- * 批量删除人员服装使用表
- *
- * @return
- */
- @RequestMapping(params = "doBatchDel")
- @ResponseBody
- public AjaxJson doBatchDel(String ids,HttpServletRequest request){
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "人员服装使用表删除成功";
- try{
- for(String id:ids.split(",")){
- ClothingUserEntity clothingUser = systemService.getEntity(ClothingUserEntity.class,
- id
- );
- clothingUserService.delete(clothingUser);
- systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
- }
- }catch(Exception e){
- e.printStackTrace();
- message = "人员服装使用表删除失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 添加人员服装使用表
- *
- * @param ids
- * @return
- */
- @RequestMapping(params = "doAdd")
- @ResponseBody
- public AjaxJson doAdd(ClothingUserEntity clothingUser, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "人员服装使用表添加成功";
- try{
- clothingUser.setQuantitykeeping(clothingUser.getQuantity());
- clothingUser.setQuantitystoped(0);
- clothingUserService.save(clothingUser);
- onhandService.updateOnhand4Use(clothingUser.getWarehouseid(), clothingUser.getClothingid(), clothingUser.getQuantity(), clothingUser.getStartdate(), "2");
- systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
- }catch(Exception e){
- e.printStackTrace();
- message = "人员服装使用表添加失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
-
- /**
- * 更新人员服装使用表
- *
- * @param ids
- * @return
- */
- @RequestMapping(params = "doUpdate")
- @ResponseBody
- public AjaxJson doUpdate(ClothingUserEntity clothingUser, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "人员服装使用表更新成功";
- ClothingUserEntity t = clothingUserService.get(ClothingUserEntity.class, clothingUser.getId());
- try {
- MyBeanUtils.copyBeanNotNull2Bean(clothingUser, t);
- clothingUserService.saveOrUpdate(t);
- systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
- } catch (Exception e) {
- e.printStackTrace();
- message = "人员服装使用表更新失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
-
- /**
- * 人员服装使用表新增页面跳转
- *
- * @return
- */
- @RequestMapping(params = "goAdd")
- public ModelAndView goAdd(ClothingUserEntity clothingUser, HttpServletRequest req) {
- if (StringUtil.isNotEmpty(clothingUser.getId())) {
- clothingUser = clothingUserService.getEntity(ClothingUserEntity.class, clothingUser.getId());
- }
- req.setAttribute("clothingUserPage", clothingUser);
- return new ModelAndView("cn/com/lzt/clothing/user/clothingUser-add");
- }
- /**
- * 人员服装使用表编辑页面跳转
- *
- * @return
- */
- @RequestMapping(params = "goUpdate")
- public ModelAndView goUpdate(ClothingUserEntity clothingUser, HttpServletRequest req) {
- if (StringUtil.isNotEmpty(clothingUser.getId())) {
- clothingUser = clothingUserService.getEntity(ClothingUserEntity.class, clothingUser.getId());
- req.setAttribute("clothingUserPage", clothingUser);
- }
- return new ModelAndView("cn/com/lzt/clothing/user/clothingUser-update");
- }
-
- /**
- * 导入功能跳转
- *
- * @return
- */
- @RequestMapping(params = "upload")
- public ModelAndView upload(HttpServletRequest req) {
- req.setAttribute("controller_name","clothingUserController");
- return new ModelAndView("common/upload/pub_excel_upload");
- }
-
- /**
- * 导出excel
- *
- * @param request
- * @param response
- */
- @RequestMapping(params = "exportXls")
- public String exportXls(ClothingUserEntity clothingUser,HttpServletRequest request,HttpServletResponse response
- , DataGrid dataGrid,ModelMap modelMap) {
- CriteriaQuery cq = new CriteriaQuery(ClothingUserEntity.class, dataGrid);
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, clothingUser, request.getParameterMap());
- List<ClothingUserEntity> clothingUsers = this.clothingUserService.getListByCriteriaQuery(cq,false);
- modelMap.put(NormalExcelConstants.FILE_NAME,"人员服装使用表");
- modelMap.put(NormalExcelConstants.CLASS,ClothingUserEntity.class);
- modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("人员服装使用表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
- "导出信息"));
- modelMap.put(NormalExcelConstants.DATA_LIST,clothingUsers);
- return NormalExcelConstants.JEECG_EXCEL_VIEW;
- }
- /**
- * 导出excel 使模板
- *
- * @param request
- * @param response
- */
- @RequestMapping(params = "exportXlsByT")
- public String exportXlsByT(ClothingUserEntity clothingUser,HttpServletRequest request,HttpServletResponse response
- , DataGrid dataGrid,ModelMap modelMap) {
- modelMap.put(NormalExcelConstants.FILE_NAME,"人员服装使用表");
- modelMap.put(NormalExcelConstants.CLASS,ClothingUserEntity.class);
- modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("人员服装使用表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
- "导出信息"));
- modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
- return NormalExcelConstants.JEECG_EXCEL_VIEW;
- }
-
- @SuppressWarnings("unchecked")
- @RequestMapping(params = "importExcel", method = RequestMethod.POST)
- @ResponseBody
- public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
- AjaxJson j = new AjaxJson();
-
- 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<ClothingUserEntity> listClothingUserEntitys = ExcelImportUtil.importExcel(file.getInputStream(),ClothingUserEntity.class,params);
- for (ClothingUserEntity clothingUser : listClothingUserEntitys) {
- clothingUserService.save(clothingUser);
- }
- j.setMsg("文件导入成功!");
- } catch (Exception e) {
- j.setMsg("文件导入失败!");
- logger.error(ExceptionUtil.getExceptionMessage(e));
- }finally{
- try {
- file.getInputStream().close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return j;
- }
-
- @RequestMapping(method = RequestMethod.GET)
- @ResponseBody
- public List<ClothingUserEntity> list() {
- List<ClothingUserEntity> listClothingUsers=clothingUserService.getList(ClothingUserEntity.class);
- return listClothingUsers;
- }
-
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- @ResponseBody
- public ResponseEntity<?> get(@PathVariable("id") String id) {
- ClothingUserEntity task = clothingUserService.get(ClothingUserEntity.class, id);
- if (task == null) {
- return new ResponseEntity(HttpStatus.NOT_FOUND);
- }
- return new ResponseEntity(task, HttpStatus.OK);
- }
- @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
- @ResponseBody
- public ResponseEntity<?> create(@RequestBody ClothingUserEntity clothingUser, UriComponentsBuilder uriBuilder) {
- //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
- Set<ConstraintViolation<ClothingUserEntity>> failures = validator.validate(clothingUser);
- if (!failures.isEmpty()) {
- return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
- }
- //保存
- try{
- clothingUserService.save(clothingUser);
- } catch (Exception e) {
- e.printStackTrace();
- return new ResponseEntity(HttpStatus.NO_CONTENT);
- }
- //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
- String id = clothingUser.getId();
- URI uri = uriBuilder.path("/rest/clothingUserController/" + id).build().toUri();
- HttpHeaders headers = new HttpHeaders();
- headers.setLocation(uri);
- return new ResponseEntity(headers, HttpStatus.CREATED);
- }
- @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity<?> update(@RequestBody ClothingUserEntity clothingUser) {
- //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
- Set<ConstraintViolation<ClothingUserEntity>> failures = validator.validate(clothingUser);
- if (!failures.isEmpty()) {
- return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
- }
- //保存
- try{
- clothingUserService.saveOrUpdate(clothingUser);
- } catch (Exception e) {
- e.printStackTrace();
- return new ResponseEntity(HttpStatus.NO_CONTENT);
- }
- //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
- return new ResponseEntity(HttpStatus.NO_CONTENT);
- }
- @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
- @ResponseStatus(HttpStatus.NO_CONTENT)
- public void delete(@PathVariable("id") String id) {
- clothingUserService.deleteEntityById(ClothingUserEntity.class, id);
- }
- // 归还
- @RequestMapping(params = "doReturn")
- @ResponseBody
- public AjaxJson doReturn(ClothingUserEntity clothingUser, HttpServletRequest request) {
- //carOnlineClientService.getAccessToken();
- String message = null;
- AjaxJson j = new AjaxJson();
- clothingUser = systemService.getEntity(ClothingUserEntity.class, clothingUser.getId());
- message = "人员服装退还成功";
- try{
- // ClothingUserEntity returnEntity = new ClothingUserEntity();
- // MyBeanUtils.copyBeanNotNull2Bean(clothingUser, returnEntity);
- // returnEntity.setId(null);
- // returnEntity.setQuantity(returnEntity.getQuantity());
- // returnEntity.setCreateDate(null);
- // returnEntity.setCreateBy(null);
- // returnEntity.setCreateName(null);
- // returnEntity.setStatus("");
- // returnEntity.setSourcetype("3");
- // clothingUserService.save(returnEntity);
- clothingUser.setQuantitykeeping(0);
- clothingUser.setQuantitystoped(clothingUser.getQuantity());
- clothingUser.setReturndate(new Date());
- clothingUser.setStatus("0");
- clothingUserService.saveOrUpdate(clothingUser);
- systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
-
- //更新现存量
- onhandService.updateOnhand4Use(clothingUser.getWarehouseid(), clothingUser.getClothingid(), clothingUser.getQuantity(), clothingUser.getStartdate(), "3");
- }catch(Exception e){
- e.printStackTrace();
- message = "人员服装退还失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
-
- @RequestMapping(params = "initList")
- public ModelAndView initList(HttpServletRequest request) {
- String userid = request.getParameter("userid");
- String postid = request.getParameter("postid");
- //找员工所属部门
- UserOrgDto userOrgDto = new UserOrgDto();
- userOrgDto.setUserId(userid);
- List<UserOrgDto> dtos = userOrgdao.getUserOrgDtoByUserId(userOrgDto , null);
- String departStr = "";
- for (UserOrgDto userOrg : dtos) {
- if(userOrg.getIfpluralism().equals("0")) {
- TSDepart dept = systemService.get(TSDepart.class, userOrg.getOrgId());
- if(dept.getOrgCode().length() == 6) {
- departStr = dept.getId();
- }else {
- departStr = dept.getTSPDepart().getId();
- }
- break;
- }
- }
- request.setAttribute("userid", userid);
- request.setAttribute("departid", departStr);
- request.setAttribute("postid", postid);
-
- return new ModelAndView("cn/com/lzt/clothing/user/clothingUserInit");
- }
-
- @RequestMapping(params = "initDetail")
- public ModelAndView initDetail(HttpServletRequest request) {
- String userid = request.getParameter("userid");
- String postid = request.getParameter("postid");
- String departid = request.getParameter("departid");
- PostEntity post = systemService.get(PostEntity.class,postid);
- List<WarehouseEntity> warehouseList = systemService.findHql("From WarehouseEntity where projectId=? ",departid);
- String warehouseid = "";
- if(warehouseList.size() > 0) {
- warehouseid = warehouseList.get(0).getId();
- }
- TSUser user = systemService.get(TSUser.class, userid);
- //性别,0 男 1 女
- String gender = user.getGender();
- String clothingtype = null;
- //根据员工性别、岗位,规范可以领取服装的范围
- if(post.getPostName().indexOf("保安") > -1) {
- if(post.getPostName().indexOf("礼仪") > -1) {
- clothingtype = "pbf";//普保女
- }else {
- clothingtype = "pbm_tb";//普保男
- }
-
- }else if(post.getPostName().indexOf("保洁") > -1) {
- clothingtype = "bj";//保洁
- if(post.getPostName().indexOf("主管") > -1)
- clothingtype +="_bgsf";
- }else if(post.getPostName().indexOf("工程") > -1 || post.getPostName().indexOf("电梯工") > -1) {
- clothingtype = "gc";//工程
- }else if(post.getPostName().indexOf("会务") > -1) {
- if(gender.equals("0")) {
- clothingtype = "hwm";//会务男
- }else {
- clothingtype = "hwf";//会务女
- }
- }else if(post.getPostName().indexOf("绿化") > -1) {
- clothingtype = "yh";
- }else if(post.getPostName().indexOf("宿管") > -1 || post.getPostName().indexOf("票务") > -1) {
- clothingtype = "sg";
- }else {
- if(gender.equals("0")) {
- clothingtype = "bgsm";
- }else {
- clothingtype = "bgsf";
- }
- }
- String clothingSql = "'"+clothingtype.replace("_", "','")+"'";
- List<ClothingEntity> clothings = systemService.findHql("From ClothingEntity where type in ("+clothingSql+")");
- List<ClothingUserEntity> clothingUserList = new ArrayList<ClothingUserEntity>();
- for (ClothingEntity clothing : clothings) {
- ClothingUserEntity cu = new ClothingUserEntity();
- cu.setUserid(userid);
- cu.setClothingid(clothing.getId());
- cu.setClothingname(clothing.getName());
- cu.setQuantity(0);
- cu.setSourcetype("4");
- cu.setUnit(clothing.getUnit());
- cu.setWarehouseid(warehouseid);
- cu.setType(clothing.getType());
- clothingUserList.add(cu);
- }
- request.setAttribute("departid", departid);
- request.setAttribute("clothingUserDetailList", clothingUserList);
-
- return new ModelAndView("cn/com/lzt/clothing/user/clothingUserDetailList");
- }
-
- @RequestMapping(params = "doInitAdd")
- @ResponseBody
- public AjaxJson doInitAdd(ClothingUserInitPage page, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "人员服装使用表初始化添加成功";
- try{
- if(page.getClothingUserDetailList().size() > 0) {
- //先删除原初始化数据,在重新插入,不做update处理
- String sql = "delete from t_b_clothing_user where userid = ?" ;
- systemService.executeSql(sql, page.getClothingUserDetailList().get(0).getUserid());
- String wid = "",wname = "";
- for (ClothingUserEntity clothingUser : page.getClothingUserDetailList()) {
- if(clothingUser.getQuantity() != null && clothingUser.getQuantity() > 0) {
- if(!wid.equals(clothingUser.getWarehouseid())) {
- wid = clothingUser.getWarehouseid();
- wname = systemService.get(WarehouseEntity.class,wid).getWarehouseName();
- }
- clothingUser.setWarehousename(wname);
- clothingUser.setQuantitykeeping(clothingUser.getQuantity());
- clothingUser.setQuantitystoped(0);
- clothingUserService.save(clothingUser);
- onhandService.updateOnhand4Use(clothingUser.getWarehouseid(), clothingUser.getClothingid(), clothingUser.getQuantity(), clothingUser.getStartdate(), "1");
- }
- }
- systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
- }
- }catch(Exception e){
- e.printStackTrace();
- message = "人员服装使用情况初始化添加失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- }
|