ICSPersonApiService.java 2.63 KB
package com.huaheng.api.U8.service;

import com.huaheng.api.U8.domain.ICSInventoryModel;
import com.huaheng.api.U8.domain.ICSPersonModel;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.general.company.domain.WarehouseCompany;
import com.huaheng.pc.general.company.mapper.WarehouseCompanyMapperAuto;
import com.huaheng.pc.system.dept.mapper.DeptMapper;
import com.huaheng.pc.system.dept.service.IDeptService;
import com.huaheng.pc.system.role.domain.Role;
import com.huaheng.pc.system.role.service.IRoleService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class ICSPersonApiService {

    @Autowired
    IUserService iUserService;

    @Autowired
    IDeptService iDeptService;
    @Resource
    private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto;

    @Transactional
    public AjaxResult ICSPerson(ICSPersonModel ICSPerson) {
        WarehouseCompany warehouseCompany = new WarehouseCompany();
        warehouseCompany.setCompanyCode(ICSPerson.getCompanyCode());
        List<WarehouseCompany> list = warehouseCompanyMapperAuto.selectListEntityByEqual(warehouseCompany);
        if (list == null || list.size() == 0){
            return AjaxResult.error("系统中没有该货主:"+warehouseCompany.toString()+"  信息,请先录入货主信息!");
        }
        int result = 0;
        User user = new User();
        user.setLoginName(ICSPerson.getcPersonCode());
        user.setUserName(ICSPerson.getcPersonName());
        //根据部门编码获取部门ID
        user.setDeptId(iDeptService.selectDeptId(ICSPerson.getcDepCode()));
        //判断系统中是否有该用户,如果有则覆盖并加上维护日期,如果没有则新增
        if (iUserService.selectUserByLoginName(ICSPerson.getcPersonCode())==null){
            user.setCreateTime(new Date());
            result = iUserService.insertUser(user);
            if (result < 1) {
                throw   new ServiceException("新增人员档案失败!");
            }
        }
        else {
            user.setUpdateTime(new Date());
            result = iUserService.updateUser(user);
            if (result < 1) {
                throw   new ServiceException("更新人员档案失败!");
            }
        }
        return AjaxResult.success("成功");
    }
}